Commit 915a2451 authored by iv's avatar iv

ERP5Workflow: PERF improve for loops

parent 08d28458
...@@ -95,9 +95,12 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -95,9 +95,12 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
chained_ptype_list = [] chained_ptype_list = []
wf_tool = getToolByName(self, 'portal_workflow') wf_tool = getToolByName(self, 'portal_workflow')
types_tool = getToolByName(self, 'portal_types') types_tool = getToolByName(self, 'portal_types')
for ptype in types_tool.objectValues():
if self.getId() in ptype.getTypeWorkflowList(): interaction_workflow_id = self.getId()
chained_ptype_list.append(ptype.getId()) append = chained_ptype_list.append
for portal_type in types_tool.objectValues():
if interaction_workflow_id in portal_type.getTypeWorkflowList():
append(portal_type.getId())
return chained_ptype_list return chained_ptype_list
security.declarePrivate('listObjectActions') security.declarePrivate('listObjectActions')
...@@ -208,8 +211,9 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -208,8 +211,9 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
security.declarePrivate('getTransitionIdList') security.declarePrivate('getTransitionIdList')
def getTransitionIdList(self): def getTransitionIdList(self):
id_list = [] id_list = []
append = id_list.append
for ob in self.objectValues(portal_type="Interaction"): for ob in self.objectValues(portal_type="Interaction"):
id_list.append(ob.getReference()) append(ob.getReference())
return id_list return id_list
security.declarePrivate('notifyWorkflowMethod') security.declarePrivate('notifyWorkflowMethod')
...@@ -229,11 +233,11 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -229,11 +233,11 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
kw = kw.copy() kw = kw.copy()
kw['workflow_method_args'] = args kw['workflow_method_args'] = args
filtered_transition_list = [] filtered_transition_list = []
append = filtered_transition_list.append
for t_id in transition_list: for t_id in transition_list:
tdef = self._getOb('interaction_' + t_id ) tdef = self._getOb('interaction_' + t_id )
assert tdef.getTriggerType() == TRIGGER_WORKFLOW_METHOD assert tdef.getTriggerType() == TRIGGER_WORKFLOW_METHOD
filtered_transition_list.append(tdef.getId()) append(tdef.getId())
former_status = {} former_status = {}
sci = StateChangeInfo( sci = StateChangeInfo(
...@@ -259,6 +263,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -259,6 +263,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
kw['workflow_method_args'] = args kw['workflow_method_args'] = args
kw['workflow_method_result'] = result kw['workflow_method_result'] = result
workflow_variable_list = self.objectValues(portal_type='Workflow Variable')
for t_id in transition_list: for t_id in transition_list:
tdef = self._getOb('interaction_' + t_id ) tdef = self._getOb('interaction_' + t_id )
assert tdef.getTriggerType() == TRIGGER_WORKFLOW_METHOD assert tdef.getTriggerType() == TRIGGER_WORKFLOW_METHOD
...@@ -271,7 +276,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -271,7 +276,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
if tdef_exprs is None: tdef_exprs = {} if tdef_exprs is None: tdef_exprs = {}
status = {} status = {}
for vdef in self.objectValues(portal_type='Workflow Variable'): for vdef in workflow_variable_list:
id = vdef.getId() id = vdef.getId()
if not vdef.getStatusIncluded(): if not vdef.getStatusIncluded():
continue continue
......
...@@ -124,10 +124,8 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -124,10 +124,8 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getDestinationReferenceList') 'getDestinationReferenceList')
def getDestinationReferenceList(self): def getDestinationReferenceList(self):
ref_list = [] return [transition.getReference() for transition
for tr in self.getDestinationValueList(): in self.getDestinationValueList()]
ref_list.append(tr.getReference())
return ref_list
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAvailableTypeList') 'getAvailableTypeList')
......
This diff is collapsed.
...@@ -75,21 +75,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject, ...@@ -75,21 +75,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
) )
def getAvailableCatalogVars(self): def getAvailableCatalogVars(self):
res = [] parent = self.getParentValue()
res.append(self.getParentValue().getStateVariable()) res = [parent.getStateVariable()]
for vdef in self.getParentValue().contentValues(portal_type="Workflow Variable"): res += [variable.getId() for variable in self.objectValues()]
if vdef.getForCatalog(): res += [variable for variable in
res.append(vdef.getId()) parent.contentValues(portal_type="Workflow Variable")
for vdef in self.objectValues(): if variable.getForCatalog()]
res.append(vdef.getId()) res.sort()
res.sort() return res
return res
def updateDynamicVariable(self): def updateDynamicVariable(self):
# Keep worklist variables updating, correspond to workflow variables. # Keep worklist variables updating, correspond to workflow variables.
# In the new workflow, we may not need this function for the moment. # In the new workflow, we may not need this function for the moment.
res = [] res = []
# XXX(WORKFLOW): is there a reason not to return self.objectValues() here?
for worklist_variable_value in self.objectValues(): for worklist_variable_value in self.objectValues():
res.append(worklist_variable_value) res.append(worklist_variable_value)
return res return res
...@@ -107,16 +106,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject, ...@@ -107,16 +106,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
variable_id = variable_value.getId() variable_id = variable_value.getId()
workflow_variable_id_list.append(variable_id) workflow_variable_id_list.append(variable_id)
worklist_variable_value = self._getOb(variable_id, None) worklist_variable_value = self._getOb(variable_id, None)
if worklist_variable_value is None and variable_value.getForCatalog() == 1 and variable_id not in default_variable_id_list: if (worklist_variable_value is None
and variable_value.getForCatalog() == 1
and variable_id not in default_variable_id_list):
variable_value_ref = variable_value.getReference() variable_value_ref = variable_value.getReference()
worklist_variable_value = self.newContent(portal_type='Worklist Variable') worklist_variable_value = self.newContent(portal_type='Worklist Variable')
worklist_variable_value.setReference(variable_value_ref) worklist_variable_value.setReference(variable_value_ref)
worklist_variable_value.setVariableExpression(variable_value.getVariableExpression()) worklist_variable_value.setVariableExpression(variable_value.getVariableExpression())
worklist_variable_value.setVariableValue(variable_value.getVariableValue()) worklist_variable_value.setVariableValue(variable_value.getVariableValue())
res.append(worklist_variable_value) res.append(worklist_variable_value)
if worklist_variable_value and worklist_variable_value not in res and variable_value.getForCatalog() == 1: if (worklist_variable_value and worklist_variable_value not in res
and variable_value.getForCatalog() == 1):
res.append(worklist_variable_value) res.append(worklist_variable_value)
if worklist_variable_value in res and variable_value.getForCatalog() == 0: if (worklist_variable_value in res
and variable_value.getForCatalog() == 0):
self._delObject(variable_id) self._delObject(variable_id)
res.remove(worklist_variable_value) res.remove(worklist_variable_value)
......
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