Commit c43e12ff authored by iv's avatar iv

ERP5Workflow: PERF: add cache on getTransitionIdList (Workflow and Interaction Workflow)

+ add addTransition in Interaction Workflow, they should add object of type Interaction not Transition
parent 1715da76
...@@ -47,6 +47,7 @@ from Products.ERP5Workflow.Document.Transition import TRIGGER_WORKFLOW_METHOD ...@@ -47,6 +47,7 @@ from Products.ERP5Workflow.Document.Transition import TRIGGER_WORKFLOW_METHOD
from Products.ERP5Workflow.Document.Workflow import Workflow from Products.ERP5Workflow.Document.Workflow import Workflow
from Products.ERP5Workflow.Document.WorkflowScript import SCRIPT_PREFIX from Products.ERP5Workflow.Document.WorkflowScript import SCRIPT_PREFIX
from types import StringTypes from types import StringTypes
from Products.ERP5Type.Cache import CachingMethod
from zLOG import LOG, INFO, WARNING from zLOG import LOG, INFO, WARNING
# show as xml library # show as xml library
...@@ -210,7 +211,26 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -210,7 +211,26 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
security.declarePrivate('getTransitionIdList') security.declarePrivate('getTransitionIdList')
def getTransitionIdList(self): def getTransitionIdList(self):
return [ob.getReference() for ob in self.objectValues(portal_type="Interaction")] def getCachedTransitionIdList():
return [transition.getReference() for transition
in self.objectValues(portal_type="Interaction")]
getCachedTransitionIdList = CachingMethod(
getCachedTransitionIdList,
id=('getCachedTransitionIdList', self.id,
self.getCacheCookie('getCachedTransitionIdList')),
cache_factory='erp5_content_long',
)
return getCachedTransitionIdList()
security.declareProtected(Permissions.AddPortalContent,
'addTransition')
def addTransition(self, name):
"""
add a new interaction to the interaction workflow
"""
tr = self.newContent(portal_type="Interaction")
tr.setReference(name)
self.newCacheCookie('getCachedTransitionIdList')
security.declarePrivate('notifyWorkflowMethod') security.declarePrivate('notifyWorkflowMethod')
def notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None): def notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None):
......
...@@ -47,7 +47,7 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed ...@@ -47,7 +47,7 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.DCWorkflow.Expression import StateChangeInfo from Products.DCWorkflow.Expression import StateChangeInfo
from Products.DCWorkflow.utils import ac_inherited_permissions, Message as _ from Products.DCWorkflow.utils import ac_inherited_permissions, Message as _
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod, CacheCookieMixin
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.DCWorkflow.Expression import createExprContext from Products.DCWorkflow.Expression import createExprContext
...@@ -97,7 +97,7 @@ def modifyRolesForPermissionDict(ob, new_permission_roles_dict): ...@@ -97,7 +97,7 @@ def modifyRolesForPermissionDict(ob, new_permission_roles_dict):
return modified_dict return modified_dict
class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
""" """
A ERP5 Workflow. A ERP5 Workflow.
""" """
...@@ -631,8 +631,16 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -631,8 +631,16 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return self.objectValues(portal_type="Transition") return self.objectValues(portal_type="Transition")
def getTransitionIdList(self): def getTransitionIdList(self):
return [transition.getReference() for transition def getCachedTransitionIdList():
in self.objectValues(portal_type="Transition")] return [transition.getReference() for transition
in self.objectValues(portal_type="Transition")]
getCachedTransitionIdList = CachingMethod(
getCachedTransitionIdList,
id=('getCachedTransitionIdList', self.id,
self.getCacheCookie('getCachedTransitionIdList')),
cache_factory='erp5_content_long',
)
return getCachedTransitionIdList()
def getScriptValueList(self): def getScriptValueList(self):
return self.objectValues(portal_type='Workflow Script') return self.objectValues(portal_type='Workflow Script')
...@@ -818,8 +826,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -818,8 +826,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
script_value_list = tdef.getAfterScriptValueList() script_value_list = tdef.getAfterScriptValueList()
if script_value_list: if script_value_list:
kwargs = form_kw kwargs = form_kw
sci = StateChangeInfo( sci = StateChangeInfo(document, self, former_status, tdef, old_sdef,
document, self, former_status, tdef, old_sdef, new_sdef, kwargs) new_sdef, kwargs)
old_state_destination_list = old_sdef.getDestinationValueList() old_state_destination_list = old_sdef.getDestinationValueList()
for script in script_value_list: for script in script_value_list:
# Script can be either script or workflow method # Script can be either script or workflow method
...@@ -877,6 +885,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -877,6 +885,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
""" """
tr = self.newContent(portal_type='Transition') tr = self.newContent(portal_type='Transition')
tr.setReference(name) tr.setReference(name)
self.newCacheCookie('getCachedTransitionIdList')
security.declareProtected(Permissions.DeleteObjects, security.declareProtected(Permissions.DeleteObjects,
'deleteTransitions') 'deleteTransitions')
......
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