[repo, ms] optimise external source deletion by using source's eid instead of name
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 07 Feb 2011 15:13:04 +0100
changeset 6941 9ed02daa7dbb
parent 6932 1599ad09624f
child 6942 18bdddd3740f
[repo, ms] optimise external source deletion by using source's eid instead of name
server/repository.py
server/sources/pyrorql.py
--- a/server/repository.py	Tue Feb 01 11:03:08 2011 +0100
+++ b/server/repository.py	Mon Feb 07 15:13:04 2011 +0100
@@ -1091,7 +1091,7 @@
             op.add_data(entity.eid)
         self._delete_info_multi(session, entities, sourceuri, extids, scleanup)
 
-    def _delete_info(self, session, entity, sourceuri, extid, scleanup=False):
+    def _delete_info(self, session, entity, sourceuri, extid, scleanup=None):
         """delete system information on deletion of an entity:
         * delete all remaining relations from/to this entity
         * call delete info on the system source which will transfer record from
@@ -1112,11 +1112,12 @@
                     rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype
                 else:
                     rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype
-                if scleanup:
+                if scleanup is not None:
                     # source cleaning: only delete relations stored locally
-                    rql += ', NOT (Y cw_source S, S name %(source)s)'
+                    # (here, scleanup
+                    rql += ', NOT (Y cw_source S, S eid %(seid)s)'
                 try:
-                    session.execute(rql, {'x': eid, 'source': sourceuri},
+                    session.execute(rql, {'x': eid, 'seid': scleanup},
                                     build_descr=False)
                 except:
                     self.exception('error while cascading delete for entity %s '
@@ -1144,12 +1145,11 @@
                     rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids)
                 else:
                     rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids)
-                if scleanup:
+                if scleanup is not None:
                     # source cleaning: only delete relations stored locally
-                    rql += ', NOT (Y cw_source S, S name %(source)s)'
+                    rql += ', NOT (Y cw_source S, S eid %(seid)s)'
                 try:
-                    session.execute(rql, {'source': sourceuri},
-                                    build_descr=False)
+                    session.execute(rql, {'seid': scleanup}, build_descr=False)
                 except:
                     self.exception('error while cascading delete for entity %s '
                                    'from %s. RQL: %s', entities, sourceuri, rql)
--- a/server/sources/pyrorql.py	Tue Feb 01 11:03:08 2011 +0100
+++ b/server/sources/pyrorql.py	Mon Feb 07 15:13:04 2011 +0100
@@ -257,7 +257,7 @@
                     if eid is not None:
                         entity = session.entity_from_eid(eid, etype)
                         repo.delete_info(session, entity, self.uri, extid,
-                                         scleanup=True)
+                                         scleanup=self.eid)
                 except:
                     self.exception('while updating %s with external id %s of source %s',
                                    etype, extid, self.uri)