Commit 5184f5ea authored by Julien Muchembled's avatar Julien Muchembled

Cache instanciation of predicates

Resource.asPredicate was broken and Base.asPredicate is useless.
parent 73b6cf17
...@@ -630,20 +630,6 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin): ...@@ -630,20 +630,6 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
# Default value is None # Default value is None
return None return None
# Predicate handling
security.declareProtected(Permissions.AccessContentsInformation,
'asPredicate')
def asPredicate(self):
"""
Returns a temporary Predicate based on the Resource properties
"""
from Products.ERP5 import newTempPredicateGroup as newTempPredicate
p = newTempPredicate(self.getId(), uid = self.getUid())
p.setMembershipCriterionBaseCategoryList(('resource',))
p.setMembershipCriterionCategoryList(('resource/%s'
% self.getRelativeUrl(),))
return p
def _pricingSortMethod(self, a, b): def _pricingSortMethod(self, a, b):
# Simple method : the one that defines a destination section wins # Simple method : the one that defines a destination section wins
if a.getDestinationSection(): if a.getDestinationSection():
......
...@@ -2957,18 +2957,6 @@ class Base( CopyContainer, ...@@ -2957,18 +2957,6 @@ class Base( CopyContainer,
return object.__of__(self) return object.__of__(self)
raise AttributeError(id) raise AttributeError(id)
# Predicate handling
security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate')
def asPredicate(self, script_id=None):
"""
This method tries to convert the current Document into a predicate
looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate
"""
script = self._getTypeBasedMethod('asPredicate', script_id=script_id)
if script is not None:
return script()
return None
def _getAcquireLocalRoles(self): def _getAcquireLocalRoles(self):
"""This method returns the value of acquire_local_roles of the object's """This method returns the value of acquire_local_roles of the object's
portal_type. portal_type.
......
...@@ -41,6 +41,7 @@ from Products.ERP5Type.Document import newTempBase ...@@ -41,6 +41,7 @@ from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Cache import readOnlyTransactionCache from Products.ERP5Type.Cache import readOnlyTransactionCache
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ZSQLCatalog.SQLCatalog import SQLQuery from Products.ZSQLCatalog.SQLCatalog import SQLQuery
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
...@@ -579,21 +580,25 @@ class Predicate(XMLObject): ...@@ -579,21 +580,25 @@ class Predicate(XMLObject):
return new_self return new_self
# Predicate handling
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'asPredicate') 'asPredicate')
def asPredicate(self, script_id=None): def asPredicate(self, script_id=None):
""" """
This method tries to convert the current Document into a predicate This method tries to convert the current Document into a predicate
looking up methods named ${PortalType}_asPredicate, looking up methods named Class_asPredictae, MetaType_asPredicate, PortalType_asPredicate
${MetaType}_asPredicate, ${Class}_asPredicate
""" """
if script_id is not None: cache = getTransactionalVariable()
script = getattr(self, script_id, None) key = id(self), script_id
if 'asPredicate' in cache:
cache = cache['asPredicate']
if key in cache:
return cache[key]
else: else:
script = self._getTypeBasedMethod('asPredicate') cache = cache['asPredicate'] = {}
script = self._getTypeBasedMethod('asPredicate', script_id)
if script is not None: if script is not None:
return script() self = script()
cache[key] = self
return self return self
def searchPredicate(self, **kw): def searchPredicate(self, **kw):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment