server/repository.py
branchstable
changeset 2101 08003e0354a7
parent 1977 606923dff11b
child 2153 d42d1eaefcdd
equal deleted inserted replaced
2100:89b825cdec74 2101:08003e0354a7
    58 
    58 
    59     def commit_event(self):
    59     def commit_event(self):
    60         """the observed connections pool has been rollbacked,
    60         """the observed connections pool has been rollbacked,
    61         remove inserted eid from repository type/source cache
    61         remove inserted eid from repository type/source cache
    62         """
    62         """
    63         self.repo.clear_caches(self.session.query_data('pendingeids', ()))
    63         try:
       
    64             self.repo.clear_caches(self.session.transaction_data['pendingeids'])
       
    65         except KeyError:
       
    66             pass
    64 
    67 
    65     def rollback_event(self):
    68     def rollback_event(self):
    66         """the observed connections pool has been rollbacked,
    69         """the observed connections pool has been rollbacked,
    67         remove inserted eid from repository type/source cache
    70         remove inserted eid from repository type/source cache
    68         """
    71         """
    69         self.repo.clear_caches(self.session.query_data('neweids', ()))
    72         try:
       
    73             self.repo.clear_caches(self.session.transaction_data['neweids'])
       
    74         except KeyError:
       
    75             pass
    70 
    76 
    71 
    77 
    72 class FTIndexEntityOp(LateOperation):
    78 class FTIndexEntityOp(LateOperation):
    73     """operation to delay entity full text indexation to commit
    79     """operation to delay entity full text indexation to commit
    74 
    80 
    78     """
    84     """
    79 
    85 
    80     def precommit_event(self):
    86     def precommit_event(self):
    81         session = self.session
    87         session = self.session
    82         entity = self.entity
    88         entity = self.entity
    83         if entity.eid in session.query_data('pendingeids', ()):
    89         if entity.eid in session.transaction_data.get('pendingeids', ()):
    84             return # entity added and deleted in the same transaction
    90             return # entity added and deleted in the same transaction
    85         session.repo.system_source.fti_unindex_entity(session, entity.eid)
    91         session.repo.system_source.fti_unindex_entity(session, entity.eid)
    86         for container in entity.fti_containers():
    92         for container in entity.fti_containers():
    87             session.repo.index_entity(session, container)
    93             session.repo.index_entity(session, container)
    88 
    94 
   862         """
   868         """
   863         # begin by inserting eid/type/source/extid into the entities table
   869         # begin by inserting eid/type/source/extid into the entities table
   864         self.system_source.add_info(session, entity, source, extid)
   870         self.system_source.add_info(session, entity, source, extid)
   865         if complete:
   871         if complete:
   866             entity.complete(entity.e_schema.indexable_attributes())
   872             entity.complete(entity.e_schema.indexable_attributes())
   867         session.add_query_data('neweids', entity.eid)
   873         new = session.transaction_data.setdefault('neweids', set())
       
   874         new.add(entity.eid)
   868         # now we can update the full text index
   875         # now we can update the full text index
   869         if self.do_fti:
   876         if self.do_fti:
   870             FTIndexEntityOp(session, entity=entity)
   877             FTIndexEntityOp(session, entity=entity)
   871         CleanupEidTypeCacheOp(session)
   878         CleanupEidTypeCacheOp(session)
   872 
   879 
   879         * update the fti
   886         * update the fti
   880         * mark eid as being deleted in session info
   887         * mark eid as being deleted in session info
   881         * setup cache update operation
   888         * setup cache update operation
   882         """
   889         """
   883         self.system_source.fti_unindex_entity(session, eid)
   890         self.system_source.fti_unindex_entity(session, eid)
   884         pending = session.query_data('pendingeids', set(), setdefault=True)
   891         pending = session.transaction_data.setdefault('pendingeids', set())
   885         pending.add(eid)
   892         pending.add(eid)
   886         CleanupEidTypeCacheOp(session)
   893         CleanupEidTypeCacheOp(session)
   887 
   894 
   888     def _delete_info(self, session, eid):
   895     def _delete_info(self, session, eid):
   889         """delete system information on deletion of an entity:
   896         """delete system information on deletion of an entity:
   916         # he can delete all its relations without security checking
   923         # he can delete all its relations without security checking
   917         session.unsafe_execute(rql, {'x': eid}, 'x', build_descr=False)
   924         session.unsafe_execute(rql, {'x': eid}, 'x', build_descr=False)
   918 
   925 
   919     def index_entity(self, session, entity):
   926     def index_entity(self, session, entity):
   920         """full text index a modified entity"""
   927         """full text index a modified entity"""
   921         alreadydone = session.query_data('indexedeids', set(), setdefault=True)
   928         alreadydone = session.transaction_data.setdefault('indexedeids', set())
   922         if entity.eid in alreadydone:
   929         if entity.eid in alreadydone:
   923             self.info('skipping reindexation of %s, already done', entity.eid)
   930             self.info('skipping reindexation of %s, already done', entity.eid)
   924             return
   931             return
   925         alreadydone.add(entity.eid)
   932         alreadydone.add(entity.eid)
   926         self.system_source.fti_index_entity(session, entity)
   933         self.system_source.fti_index_entity(session, entity)