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