def initialize(self, items): for i, categ in enumerate(items, 1): cat = IndexedCategory(id=categ.getId(), title=categ.getTitle()) db.session.add(cat) if i % 1000 == 0: db.session.commit() db.session.commit()
def index(self, obj): if not obj.getId(): # newly created root category has id='' return self.unindex(obj) category = IndexedCategory(id=obj.getId(), title=obj.getTitle()) db.session.add(category) with retry_request_on_conflict(): db.session.flush()