Commit ce57c6af authored by Julien Muchembled's avatar Julien Muchembled

Fix possible performance issues with transactional_cached decorator

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39032 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 75eaa480
...@@ -37,7 +37,7 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery ...@@ -37,7 +37,7 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
@transactional_cached() @transactional_cached()
def _getEffectiveModel(self, start_date=None, stop_date=None): def _getEffectiveModel(self, start_date, stop_date):
"""Return the most appropriate model using effective_date, expiration_date """Return the most appropriate model using effective_date, expiration_date
and version number. and version number.
An effective model is a model which start and stop_date are equal (or An effective model is a model which start and stop_date are equal (or
...@@ -79,7 +79,7 @@ def _getEffectiveModel(self, start_date=None, stop_date=None): ...@@ -79,7 +79,7 @@ def _getEffectiveModel(self, start_date=None, stop_date=None):
@transactional_cached() @transactional_cached()
def _findPredicateList(container_list, portal_type=None): def _findPredicateList(container_list, portal_type):
predicate_list = [] predicate_list = []
reference_dict = {} reference_dict = {}
for container in container_list: for container in container_list:
...@@ -164,7 +164,9 @@ class CompositionMixin: ...@@ -164,7 +164,9 @@ class CompositionMixin:
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'asComposedDocument') 'asComposedDocument')
asComposedDocument = transactional_cached()(asComposedDocument) asComposedDocument = transactional_cached(
lambda self, portal_type_list=None: (self, portal_type_list)
)(asComposedDocument)
# XXX add accessors to get properties from '_effective_model_list' ? # XXX add accessors to get properties from '_effective_model_list' ?
# (cf PaySheetModel) # (cf PaySheetModel)
......
...@@ -334,9 +334,15 @@ def caching_instance_method(*args, **kw): ...@@ -334,9 +334,15 @@ def caching_instance_method(*args, **kw):
return lambda *args, **kw: caching_method(*args, **kw) return lambda *args, **kw: caching_method(*args, **kw)
return decorator return decorator
def transactional_cached(key_method=lambda *args: args): _default_key_method = lambda *args: args
def transactional_cached(key_method=_default_key_method):
@simple_decorator @simple_decorator
def decorator(function): def decorator(function):
# Unfornately, we can only check functions (not other callable like class).
assert (key_method is not _default_key_method or
not getattr(function, 'func_defaults', None)), (
"default 'key_method' of 'transactional_cached' does not work with"
" functions having default values for parameters")
key = repr(function) key = repr(function)
def wrapper(*args, **kw): def wrapper(*args, **kw):
cache = getTransactionalVariable().setdefault(key, {}) cache = getTransactionalVariable().setdefault(key, {})
......
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