653 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
653 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
654 # now we can update the full text index |
654 # now we can update the full text index |
655 if self.do_fti and self.need_fti_indexation(entity.__regid__): |
655 if self.do_fti and self.need_fti_indexation(entity.__regid__): |
656 if complete: |
656 if complete: |
657 entity.complete(entity.e_schema.indexable_attributes()) |
657 entity.complete(entity.e_schema.indexable_attributes()) |
658 FTIndexEntityOp(session, entity=entity) |
658 self.index_entity(session, entity=entity) |
659 |
659 |
660 def update_info(self, session, entity, need_fti_update): |
660 def update_info(self, session, entity, need_fti_update): |
661 """mark entity as being modified, fulltext reindex if needed""" |
661 """mark entity as being modified, fulltext reindex if needed""" |
662 if self.do_fti and need_fti_update: |
662 if self.do_fti and need_fti_update: |
663 # reindex the entity only if this query is updating at least |
663 # reindex the entity only if this query is updating at least |
664 # one indexable attribute |
664 # one indexable attribute |
665 FTIndexEntityOp(session, entity=entity) |
665 self.index_entity(session, entity=entity) |
666 # update entities.mtime. |
666 # update entities.mtime. |
667 # XXX Only if entity.__regid__ in self.multisources_etypes? |
667 # XXX Only if entity.__regid__ in self.multisources_etypes? |
668 attrs = {'eid': entity.eid, 'mtime': datetime.now()} |
668 attrs = {'eid': entity.eid, 'mtime': datetime.now()} |
669 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
669 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
670 |
670 |
1026 |
1026 |
1027 def index_entity(self, session, entity): |
1027 def index_entity(self, session, entity): |
1028 """create an operation to [re]index textual content of the given entity |
1028 """create an operation to [re]index textual content of the given entity |
1029 on commit |
1029 on commit |
1030 """ |
1030 """ |
1031 FTIndexEntityOp(session, entity=entity) |
1031 hook.set_operation(session, 'ftindex', entity.eid, FTIndexEntityOp) |
1032 |
1032 |
1033 def fti_unindex_entity(self, session, eid): |
1033 def fti_unindex_entity(self, session, eid): |
1034 """remove text content for entity with the given eid from the full text |
1034 """remove text content for entity with the given eid from the full text |
1035 index |
1035 index |
1036 """ |
1036 """ |
1060 precommit operation which may add relations to the entity |
1060 precommit operation which may add relations to the entity |
1061 """ |
1061 """ |
1062 |
1062 |
1063 def precommit_event(self): |
1063 def precommit_event(self): |
1064 session = self.session |
1064 session = self.session |
1065 entity = self.entity |
|
1066 if entity.eid in session.transaction_data.get('pendingeids', ()): |
|
1067 return # entity added and deleted in the same transaction |
|
1068 alreadydone = session.transaction_data.setdefault('indexedeids', set()) |
|
1069 if entity.eid in alreadydone: |
|
1070 self.debug('skipping reindexation of %s, already done', entity.eid) |
|
1071 return |
|
1072 alreadydone.add(entity.eid) |
|
1073 source = session.repo.system_source |
1065 source = session.repo.system_source |
1074 for container in entity.fti_containers(): |
1066 pendingeids = session.transaction_data.get('pendingeids', ()) |
1075 source.fti_unindex_entity(session, container.eid) |
1067 done = session.transaction_data.setdefault('indexedeids', set()) |
1076 source.fti_index_entity(session, container) |
1068 for eid in session.transaction_data.pop('ftindex', ()): |
1077 |
1069 if eid in pendingeids or eid in done: |
1078 def commit_event(self): |
1070 # entity added and deleted in the same transaction or already |
1079 pass |
1071 # processed |
|
1072 return |
|
1073 done.add(eid) |
|
1074 for container in session.entity_from_eid(eid).fti_containers(): |
|
1075 source.fti_unindex_entity(session, container.eid) |
|
1076 source.fti_index_entity(session, container) |
1080 |
1077 |
1081 |
1078 |
1082 def sql_schema(driver): |
1079 def sql_schema(driver): |
1083 helper = get_db_helper(driver) |
1080 helper = get_db_helper(driver) |
1084 typemap = helper.TYPE_MAPPING |
1081 typemap = helper.TYPE_MAPPING |