[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 14 Jun 2011 15:37:09 +0200
branchstable
changeset 7502 e7190f7e850e
parent 7501 2983dd24494a
child 7503 bc30c2faaadc
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
hooks/integrity.py
hooks/metadata.py
server/repository.py
server/session.py
--- a/hooks/integrity.py	Tue Jun 14 15:37:09 2011 +0200
+++ b/hooks/integrity.py	Tue Jun 14 15:37:09 2011 +0200
@@ -121,10 +121,10 @@
             return
         session = self._cw
         eidfrom, eidto = self.eidfrom, self.eidto
-        pendingrdefs = session.transaction_data.get('pendingrdefs', ())
-        if (session.describe(eidfrom)[0], rtype, session.describe(eidto)[0]) in pendingrdefs:
+        rdef = session.rtype_eids_rdef(rtype, eidfrom, eidto)
+        if (rdef.subject, rtype, rdef.object) in session.transaction_data.get('pendingrdefs', ()):
             return
-        card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality')
+        card = rdef.cardinality
         if card[0] in '1+' and not session.deleted_in_transaction(eidfrom):
             _CheckSRelationOp.get_instance(session).add_data((eidfrom, rtype))
         if card[1] in '1+' and not session.deleted_in_transaction(eidto):
@@ -190,8 +190,8 @@
 
     def __call__(self):
         # XXX get only RQL[Unique]Constraints?
-        constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
-                                                'constraints')
+        rdef = self._cw.rtype_eids_rdef(self.rtype, self.eidfrom, self.eidto)
+        constraints = rdef.constraints
         if constraints:
             _CheckConstraintsOp.get_instance(self._cw).add_data(
                 (self.eidfrom, self.rtype, self.eidto, constraints))
@@ -341,15 +341,15 @@
     def __call__(self):
         # if the relation is being delete, don't delete composite's components
         # automatically
-        pendingrdefs = self._cw.transaction_data.get('pendingrdefs', ())
-        if (self._cw.describe(self.eidfrom)[0], self.rtype,
-            self._cw.describe(self.eidto)[0]) in pendingrdefs:
+        session = self._cw
+        rtype = self.rtype
+        rdef = session.rtype_eids_rdef(rtype, self.eidfrom, self.eidto)
+        if (rdef.subject, rtype, rdef.object) in session.transaction_data.get('pendingrdefs', ()):
             return
-        composite = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
-                                              'composite')
+        composite = rdef.composite
         if composite == 'subject':
             _DelayedDeleteOEntityOp.get_instance(self._cw).add_data(
-                (self.eidto, self.rtype))
+                (self.eidto, rtype))
         elif composite == 'object':
             _DelayedDeleteSEntityOp.get_instance(self._cw).add_data(
-                (self.eidfrom, self.rtype))
+                (self.eidfrom, rtype))
--- a/hooks/metadata.py	Tue Jun 14 15:37:09 2011 +0200
+++ b/hooks/metadata.py	Tue Jun 14 15:37:09 2011 +0200
@@ -106,7 +106,7 @@
             # skip this special composite relation # XXX (syt) why?
             return
         eidfrom, eidto = self.eidfrom, self.eidto
-        composite = self._cw.schema_rproperty(self.rtype, eidfrom, eidto, 'composite')
+        composite = self._cw.rtype_eids_rdef(self.rtype, eidfrom, eidto).composite
         if composite == 'subject':
             SyncOwnersOp.get_instance(self._cw).add_data( (eidfrom, eidto) )
         elif composite == 'object':
--- a/server/repository.py	Tue Jun 14 15:37:09 2011 +0200
+++ b/server/repository.py	Tue Jun 14 15:37:09 2011 +0200
@@ -103,7 +103,8 @@
     if session.is_internal_session \
            or not session.is_hook_category_activated('activeintegrity'):
         return
-    card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality')
+    rdef = session.rtype_eids_rdef(rtype, eidfrom, eidto)
+    card = rdef.cardinality
     # one may be tented to check for neweids but this may cause more than one
     # relation even with '1?'  cardinality if thoses relations are added in the
     # same transaction where the entity is being created. This never occurs from
@@ -115,7 +116,7 @@
     # * inlined relations will be implicitly deleted for the subject entity
     # * we don't want read permissions to be applied but we want delete
     #   permission to be checked
-    if card[0] in '1?' and not session.repo.schema.rschema(rtype).inlined:
+    if card[0] in '1?' and not rdef.rtype.inlined:
         with security_enabled(session, read=False):
             session.execute('DELETE X %s Y WHERE X eid %%(x)s, '
                             'NOT Y eid %%(y)s' % rtype,
--- a/server/session.py	Tue Jun 14 15:37:09 2011 +0200
+++ b/server/session.py	Tue Jun 14 15:37:09 2011 +0200
@@ -431,12 +431,12 @@
         """
         return eid in self.transaction_data.get('neweids', ())
 
-    def schema_rproperty(self, rtype, eidfrom, eidto, rprop):
-        rschema = self.repo.schema[rtype]
-        subjtype = self.describe(eidfrom)[0]
-        objtype = self.describe(eidto)[0]
-        rdef = rschema.rdef(subjtype, objtype)
-        return rdef.get(rprop)
+    def rtype_eids_rdef(self, rtype, eidfrom, eidto):
+        # use type_and_source_from_eid instead of type_from_eid for optimization
+        # (avoid two extra methods call)
+        subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
+        objtype = self.repo.type_and_source_from_eid(eidto, self)[0]
+        return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)]
 
     # security control #########################################################
 
@@ -1070,6 +1070,11 @@
 
     # deprecated ###############################################################
 
+    @deprecated('[3.13] use getattr(session.rtype_eids_rdef(rtype, eidfrom, eidto), prop)')
+    def schema_rproperty(self, rtype, eidfrom, eidto, rprop):
+        return getattr(self.rtype_eids_rdef(rtype, eidfrom, eidto), rprop)
+
+
     @deprecated("[3.7] execute is now unsafe by default in hooks/operation. You"
                 " can also control security with the security_enabled context "
                 "manager")