Commit 2276d7ac authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use CachingMethod for caching workflow actions.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@936 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d082162f
......@@ -303,10 +303,7 @@ from Products.CMFCore.utils import getToolByName
from DocumentTemplate.DT_Util import TemplateDict
from Products.CMFCore.utils import _getAuthenticatedUser
from time import time
GLOBAL_WORKFLOW_ACTION_CACHE_DURATION = 300
cached_workflow_global_actions = {}
cached_workflow_global_actions_time = {}
from Products.ERP5Type.Cache import CachingMethod
class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
......@@ -317,12 +314,7 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
Called on every request.
Returns the actions to be displayed to the user.
'''
# Return Cache
user = str(_getAuthenticatedUser(self))
if cached_workflow_global_actions.has_key((user, self.id)):
if time() - cached_workflow_global_actions_time[(user, self.id)] < GLOBAL_WORKFLOW_ACTION_CACHE_DURATION:
return cached_workflow_global_actions[(user, self.id)]
def _listGlobalActions(user=None, id=None):
if not self.worklists:
return None # Optimization
sm = getSecurityManager()
......@@ -372,9 +364,13 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
'category': qdef.actbox_category}))
fmt_data._pop()
res.sort()
cached_workflow_global_actions[(user, self.id)] = map((lambda (id, val): val), res)
cached_workflow_global_actions_time[(user, self.id)] = time()
return cached_workflow_global_actions[(user, self.id)]
return map((lambda (id, val): val), res)
# Return Cache
_listGlobalActions = CachingMethod(_listGlobalActions, id='listGlobalActions', cache_duration = 300)
user = str(_getAuthenticatedUser(self))
return _listGlobalActions(user=user, id=self.id)
DCWorkflowDefinition.listGlobalActions = PatchedDCWorkflowDefinition.listGlobalActions
......
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