Commit 915a2451 authored by iv's avatar iv

ERP5Workflow: PERF improve for loops

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