[repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 29 Mar 2010 13:28:41 +0200
branchstable
changeset 5059 1d5c81588144
parent 5058 6dfeb8e75188
child 5060 ee3b856e1406
[repo] make etype which should go in deleted_entities configurable: we only need this for types imported from other multi-sources instances
server/serverconfig.py
server/sources/native.py
--- a/server/serverconfig.py	Mon Mar 29 13:26:20 2010 +0200
+++ b/server/serverconfig.py	Mon Mar 29 13:28:41 2010 +0200
@@ -141,6 +141,14 @@
 kept (hence undoable).',
           'group': 'main', 'inputlevel': 1,
           }),
+        ('multi-sources-etypes',
+         {'type' : 'csv', 'default': (),
+          'help': 'defines which entity types from this repository are used \
+by some other instances. You should set this properly so those instances to \
+detect updates / deletions.',
+          'group': 'main', 'inputlevel': 1,
+          }),
+
         ('delay-full-text-indexation',
          {'type' : 'yn', 'default': False,
           'help': 'When full text indexation of entity has a too important cost'
--- a/server/sources/native.py	Mon Mar 29 13:26:20 2010 +0200
+++ b/server/sources/native.py	Mon Mar 29 13:28:41 2010 +0200
@@ -194,6 +194,8 @@
         self._eid_creation_lock = Lock()
         # (etype, attr) / storage mapping
         self._storages = {}
+        # entity types that may be used by other multi-sources instances
+        self.multisources_etypes = set(repo.config['multi-sources-etypes'])
         # XXX no_sqlite_wrap trick since we've a sqlite locking pb when
         # running unittest_multisources with the wrapping below
         if self.dbdriver == 'sqlite' and \
@@ -659,16 +661,21 @@
             # reindex the entity only if this query is updating at least
             # one indexable attribute
             FTIndexEntityOp(session, entity=entity)
-        # update entities.mtime
+        # update entities.mtime.
+        # XXX Only if entity.__regid__ in self.multisources_etypes?
         attrs = {'eid': entity.eid, 'mtime': datetime.now()}
         self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs)
 
     def delete_info(self, session, entity, uri, extid):
-        """delete system information on deletion of an entity by transfering
-        record from the entities table to the deleted_entities table
+        """delete system information on deletion of an entity:
+        * remove record from the entities table
+        * transfer it to the deleted_entities table if the entity's type is
+          multi-sources
         """
         attrs = {'eid': entity.eid}
         self.doexec(session, self.sqlgen.delete('entities', attrs), attrs)
+        if not entity.__regid__ in self.multisources_etypes:
+            return
         if extid is not None:
             assert isinstance(extid, str), type(extid)
             extid = b64encode(extid)
@@ -685,6 +692,11 @@
         * list of (etype, eid) of entities of the given types which have been
           deleted since the given timestamp
         """
+        for etype in etypes:
+            if not etype in self.multisources_etypes:
+                self.critical('%s not listed as a multi-sources entity types. '
+                              'Modify your configuration')
+                self.multisources_etypes.add(etype)
         modsql = _modified_sql('entities', etypes)
         cursor = self.doexec(session, modsql, {'time': mtime})
         modentities = cursor.fetchall()
@@ -931,8 +943,10 @@
         self.doexec(session, sql, action.changes)
         # restore record in entities (will update fti if needed)
         self.add_info(session, entity, self, None, True)
-        # remove record from deleted_entities
-        self.doexec(session, 'DELETE FROM deleted_entities WHERE eid=%s' % eid)
+        # remove record from deleted_entities if entity's type is multi-sources
+        if entity.__regid__ in self.multisources_etypes:
+            self.doexec(session,
+                        'DELETE FROM deleted_entities WHERE eid=%s' % eid)
         self.repo.hm.call_hooks('after_add_entity', session, entity=entity)
         return errors