do not delay sync queries to an operation, it may cause pb (nosy list propagation for instance) 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Sep 2009 16:38:08 +0200
branch3.5
changeset 3088 854a30d8c092
parent 3084 096d680c9da2
child 3089 72c23fc7fe20
do not delay sync queries to an operation, it may cause pb (nosy list propagation for instance)
server/hooksmanager.py
--- a/server/hooksmanager.py	Wed Sep 02 10:23:38 2009 +0200
+++ b/server/hooksmanager.py	Wed Sep 02 16:38:08 2009 +0200
@@ -273,12 +273,6 @@
 
 from cubicweb.server.pool import PreCommitOperation
 
-class RQLPrecommitOperation(PreCommitOperation):
-    def precommit_event(self):
-        execute = self.session.unsafe_execute
-        for rql in self.rqls:
-            execute(*rql)
-
 
 class PropagateSubjectRelationHook(Hook):
     """propagate permissions and nosy list when new entity are added"""
@@ -299,10 +293,10 @@
         else:
             assert rtype in self.object_relations
             meid, seid = toeid, fromeid
-        rql = 'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\
-              % (self.rtype, self.rtype, self.rtype)
-        rqls = [(rql, {'x': meid, 'e': seid}, ('x', 'e'))]
-        RQLPrecommitOperation(session, rqls=rqls)
+        session.unsafe_execute(
+            'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\
+            % (self.rtype, self.rtype, self.rtype),
+            {'x': meid, 'e': seid}, ('x', 'e'))
 
 
 class PropagateSubjectRelationAddHook(Hook):
@@ -316,19 +310,17 @@
 
     def call(self, session, fromeid, rtype, toeid):
         eschema = self.schema.eschema(session.describe(fromeid)[0])
-        rqls = []
+        execute = session.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
-                rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'X %s R, NOT R %s P' % (rtype, rel, rtype),
-                             {'x': fromeid, 'p': toeid}, 'x'))
+                execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'X %s R, NOT R %s P' % (rtype, rel, rtype),
+                        {'x': fromeid, 'p': toeid}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
-                rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'R %s X, NOT R %s P' % (rtype, rel, rtype),
-                             {'x': fromeid, 'p': toeid}, 'x'))
-        if rqls:
-            RQLPrecommitOperation(session, rqls=rqls)
+                execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'R %s X, NOT R %s P' % (rtype, rel, rtype),
+                        {'x': fromeid, 'p': toeid}, 'x')
 
 
 class PropagateSubjectRelationDelHook(Hook):
@@ -342,16 +334,14 @@
 
     def call(self, session, fromeid, rtype, toeid):
         eschema = self.schema.eschema(session.describe(fromeid)[0])
-        rqls = []
+        execute = session.unsafe_execute
         for rel in self.subject_relations:
             if eschema.has_subject_relation(rel):
-                rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'X %s R' % (rtype, rel),
-                             {'x': fromeid, 'p': toeid}, 'x'))
+                execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'X %s R' % (rtype, rel),
+                        {'x': fromeid, 'p': toeid}, 'x')
         for rel in self.object_relations:
             if eschema.has_object_relation(rel):
-                rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
-                             'R %s X' % (rtype, rel),
-                             {'x': fromeid, 'p': toeid}, 'x'))
-        if rqls:
-            RQLPrecommitOperation(session, rqls=rqls)
+                execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, '
+                        'R %s X' % (rtype, rel),
+                        {'x': fromeid, 'p': toeid}, 'x')