Пример #1
0
 def init(self):
     """
     Re-initialize all indexes. This calls rebuild on every registered
     index class. There be dragons here.
     :return: None
     """
     for name in self._indexes.keys():
         Log.debug("Init on %s" % name)
         try:
             self.rebuild(self._indexes.get(name))
         except NotFoundError or KeyError or AttributeError as e:
             Log.warning("Error re-initing index %s: %s" % (name, e))
Пример #2
0
    def _build_tree(self, passes, root=root_node):
        tree = Tree()

        pgconn = Registry.get_database_connection()
        with pgconn.get_session() as session:

            tree.create_node(root, root)
            for item in IngredientModel.get_by_kind(session, CategoryKind):
                tree.create_node(item.slug,
                                 item.slug,
                                 parent=root,
                                 data=self._create_tree_data(item))

            for item in IngredientModel.get_by_kind(session, FamilyKind):
                tree.create_node(item.slug,
                                 item.slug,
                                 parent=item.parent,
                                 data=self._create_tree_data(item))

            ingredients_to_place = list(
                IngredientModel.get_usable_ingredients(session))
            for i in range(1, passes + 1):
                Log.debug("Pass %i/%i" % (i, passes))

                for item in ingredients_to_place[:]:
                    if item.kind == FamilyKind.value:
                        ingredients_to_place.remove(item)
                        Log.debug("Skipping %s because it is a family." %
                                  item.slug)
                        continue
                    try:
                        tree.create_node(item.slug,
                                         item.slug,
                                         parent=item.parent,
                                         data=self._create_tree_data(item))
                        ingredients_to_place.remove(item)
                    except NodeIDAbsentError:
                        Log.debug("skipping %s (Attempt %i/%s)" %
                                  (item.slug, i, passes))

                if len(ingredients_to_place) == 0:
                    Log.info("All done after pass %i" % i)
                    break

        return tree