Commit 6bf88a5c authored by Alexandre Boeglin's avatar Alexandre Boeglin

as _getTypeBasedMethod can be called a lot within a short period for the same

method_id on objects with the same portal type (for instance, asPredicate,
during a predicate search), caching its result is much faster than looking for
the same script in a nearly identical acquisition path each time.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17492 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 373c83a8
...@@ -2692,24 +2692,28 @@ class Base( CopyContainer, ...@@ -2692,24 +2692,28 @@ class Base( CopyContainer,
fallback_script_id : the script to use if nothing is found fallback_script_id : the script to use if nothing is found
""" """
def cached_getattr(portal_type, method_id):
script_name_end = '_%s' % method_id
for script_name_begin in [portal_type, self.getMetaType(),
self.__class__.__name__]:
name = ''.join([script_name_begin.replace(' ',''), script_name_end])
script = getattr(self, name, None)
if script is not None:
return script
cached_getattr = CachingMethod(cached_getattr, id='Base__getattr',
cache_factory='erp5_content_long')
# script_id should not be used any more, keep compatibility # script_id should not be used any more, keep compatibility
if script_id is not None: if script_id is not None:
LOG('ERP5Type/Base.getTypeBaseMethod',0, LOG('ERP5Type/Base.getTypeBaseMethod',0,
'DEPRECATED script_id parameter is used') 'DEPRECATED script_id parameter is used')
fallback_script_id=script_id fallback_script_id=script_id
script_name = ''
script = None
script_name_end = '_%s' % method_id
# Look at a local script which # Look at a local script which
# can return a new predicate. # can return a new predicate.
for script_name_begin in [self.getPortalType(), self.getMetaType(), self.__class__.__name__]: script = cached_getattr(self.getPortalType(), method_id)
script_name = join([script_name_begin.replace(' ',''), script_name_end ], '')
script = getattr(self, script_name, None)
if script is not None: if script is not None:
break return script.__of__(self)
if script is None and fallback_script_id is not None: if fallback_script_id is not None:
script = getattr(self, fallback_script_id) return getattr(self, fallback_script_id)
return script
# Predicate handling # Predicate handling
security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate') security.declareProtected(Permissions.AccessContentsInformation, 'asPredicate')
......
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