1218 return [session._( |
1218 return [session._( |
1219 "Can't undo creation of entity %(eid)s of type %(etype)s, type " |
1219 "Can't undo creation of entity %(eid)s of type %(etype)s, type " |
1220 "no more supported" % {'eid': eid, 'etype': etype})] |
1220 "no more supported" % {'eid': eid, 'etype': etype})] |
1221 entity.eid = eid |
1221 entity.eid = eid |
1222 # for proper eid/type cache update |
1222 # for proper eid/type cache update |
1223 hook.set_operation(session, 'pendingeids', eid, |
1223 CleanupDeletedEidsCacheOp.get_instance(session).add_data(eid) |
1224 CleanupDeletedEidsCacheOp) |
|
1225 self.repo.hm.call_hooks('before_delete_entity', session, entity=entity) |
1224 self.repo.hm.call_hooks('before_delete_entity', session, entity=entity) |
1226 # remove is / is_instance_of which are added using sql by hooks, hence |
1225 # remove is / is_instance_of which are added using sql by hooks, hence |
1227 # unvisible as transaction action |
1226 # unvisible as transaction action |
1228 self.doexec(session, 'DELETE FROM is_relation WHERE eid_from=%s' % eid) |
1227 self.doexec(session, 'DELETE FROM is_relation WHERE eid_from=%s' % eid) |
1229 self.doexec(session, 'DELETE FROM is_instance_of_relation WHERE eid_from=%s' % eid) |
1228 self.doexec(session, 'DELETE FROM is_instance_of_relation WHERE eid_from=%s' % eid) |
1286 |
1285 |
1287 def index_entity(self, session, entity): |
1286 def index_entity(self, session, entity): |
1288 """create an operation to [re]index textual content of the given entity |
1287 """create an operation to [re]index textual content of the given entity |
1289 on commit |
1288 on commit |
1290 """ |
1289 """ |
1291 hook.set_operation(session, 'ftindex', entity.eid, FTIndexEntityOp) |
1290 FTIndexEntityOp.get_instance(session).add_data(entity.eid) |
1292 |
1291 |
1293 def fti_unindex_entity(self, session, eid): |
1292 def fti_unindex_entity(self, session, eid): |
1294 """remove text content for entity with the given eid from the full text |
1293 """remove text content for entity with the given eid from the full text |
1295 index |
1294 index |
1296 """ |
1295 """ |
1311 session.pool['system']) |
1310 session.pool['system']) |
1312 except Exception: # let KeyboardInterrupt / SystemExit propagate |
1311 except Exception: # let KeyboardInterrupt / SystemExit propagate |
1313 self.exception('error while reindexing %s', entity) |
1312 self.exception('error while reindexing %s', entity) |
1314 |
1313 |
1315 |
1314 |
1316 class FTIndexEntityOp(hook.LateOperation): |
1315 class FTIndexEntityOp(hook.DataOperationMixIn, hook.LateOperation): |
1317 """operation to delay entity full text indexation to commit |
1316 """operation to delay entity full text indexation to commit |
1318 |
1317 |
1319 since fti indexing may trigger discovery of other entities, it should be |
1318 since fti indexing may trigger discovery of other entities, it should be |
1320 triggered on precommit, not commit, and this should be done after other |
1319 triggered on precommit, not commit, and this should be done after other |
1321 precommit operation which may add relations to the entity |
1320 precommit operation which may add relations to the entity |
1324 def precommit_event(self): |
1323 def precommit_event(self): |
1325 session = self.session |
1324 session = self.session |
1326 source = session.repo.system_source |
1325 source = session.repo.system_source |
1327 pendingeids = session.transaction_data.get('pendingeids', ()) |
1326 pendingeids = session.transaction_data.get('pendingeids', ()) |
1328 done = session.transaction_data.setdefault('indexedeids', set()) |
1327 done = session.transaction_data.setdefault('indexedeids', set()) |
1329 for eid in session.transaction_data.pop('ftindex', ()): |
1328 for eid in self.get_data(): |
1330 if eid in pendingeids or eid in done: |
1329 if eid in pendingeids or eid in done: |
1331 # entity added and deleted in the same transaction or already |
1330 # entity added and deleted in the same transaction or already |
1332 # processed |
1331 # processed |
1333 return |
1332 return |
1334 done.add(eid) |
1333 done.add(eid) |