Commit 9d956563 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/sandbox/amount_generator@37798 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5df0f2b7
...@@ -38,7 +38,7 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery ...@@ -38,7 +38,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
...@@ -85,7 +85,7 @@ def _getEffectiveModel(self, start_date=None, stop_date=None): ...@@ -85,7 +85,7 @@ def _getEffectiveModel(self, start_date=None, stop_date=None):
# _findPredicateList's cache has at most 1 entry per specialise value found # _findPredicateList's cache has at most 1 entry per specialise value found
# on SO/SOL. # on SO/SOL.
@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:
...@@ -169,7 +169,9 @@ class CompositionMixin: ...@@ -169,7 +169,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)
......
...@@ -294,9 +294,15 @@ def caching_instance_method(*args, **kw): ...@@ -294,9 +294,15 @@ def caching_instance_method(*args, **kw):
return lambda *args, **kw: caching_method(*args, **kw) return lambda *args, **kw: caching_method(*args, **kw)
return wrapped return wrapped
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(None).setdefault(key, {}) cache = getTransactionalVariable(None).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