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 ...@@ -303,10 +303,7 @@ from Products.CMFCore.utils import getToolByName
from DocumentTemplate.DT_Util import TemplateDict from DocumentTemplate.DT_Util import TemplateDict
from Products.CMFCore.utils import _getAuthenticatedUser from Products.CMFCore.utils import _getAuthenticatedUser
from time import time from time import time
from Products.ERP5Type.Cache import CachingMethod
GLOBAL_WORKFLOW_ACTION_CACHE_DURATION = 300
cached_workflow_global_actions = {}
cached_workflow_global_actions_time = {}
class PatchedDCWorkflowDefinition(DCWorkflowDefinition): class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
...@@ -317,12 +314,7 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition): ...@@ -317,12 +314,7 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
Called on every request. Called on every request.
Returns the actions to be displayed to the user. Returns the actions to be displayed to the user.
''' '''
# Return Cache def _listGlobalActions(user=None, id=None):
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)]
if not self.worklists: if not self.worklists:
return None # Optimization return None # Optimization
sm = getSecurityManager() sm = getSecurityManager()
...@@ -372,9 +364,13 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition): ...@@ -372,9 +364,13 @@ class PatchedDCWorkflowDefinition(DCWorkflowDefinition):
'category': qdef.actbox_category})) 'category': qdef.actbox_category}))
fmt_data._pop() fmt_data._pop()
res.sort() res.sort()
cached_workflow_global_actions[(user, self.id)] = map((lambda (id, val): val), res) return map((lambda (id, val): val), res)
cached_workflow_global_actions_time[(user, self.id)] = time()
return cached_workflow_global_actions[(user, self.id)] # 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 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