Commit b40fe901 authored by iv's avatar iv

ERP5Workflow: PERF: avoid calling multiple times the same methods

parent 16194e30
...@@ -243,8 +243,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -243,8 +243,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
sci = StateChangeInfo( sci = StateChangeInfo(
ob, self, former_status, tdef, None, None, kwargs=kw) ob, self, former_status, tdef, None, None, kwargs=kw)
before_script_list = tdef.getBeforeScriptValueList() for script in tdef.getBeforeScriptValueList():
for script in before_script_list:
if script: if script:
script_context = self._asScriptContext() script_context = self._asScriptContext()
script = getattr(script_context, script.id) script = getattr(script_context, script.id)
...@@ -486,8 +485,6 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -486,8 +485,6 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
sub_object = SubElement(variable, property_id, attrib=dict(type='int')) sub_object = SubElement(variable, property_id, attrib=dict(type='int'))
elif property_id == 'variable_value': elif property_id == 'variable_value':
property_value = vdef.getVariableValue() property_value = vdef.getVariableValue()
if vdef.getVariableValue() is not None:
property_value = vdef.getVariableValue()
sub_object = SubElement(variable, property_id, attrib=dict(type='string')) sub_object = SubElement(variable, property_id, attrib=dict(type='string'))
else: else:
property_value = vdef.getProperty(property_id) property_value = vdef.getProperty(property_id)
......
...@@ -197,11 +197,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -197,11 +197,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
Returns a true value if the given info name is supported. Returns a true value if the given info name is supported.
''' '''
if name == self.getStateVariable(): if name == self.getStateVariable():
return 1 return True
vdef = self.getVariableValueDict().get(name, None) return self.getVariableValueDict().get(name, None) is not None
if vdef is None:
return 0
return 1
def _checkTransitionGuard(self, transition, document, **kw): def _checkTransitionGuard(self, transition, document, **kw):
return transition.checkGuard(getSecurityManager(), self, document, **kw) return transition.checkGuard(getSecurityManager(), self, document, **kw)
...@@ -378,7 +375,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -378,7 +375,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
(worklist id as key) and which value is a dict composed of (worklist id as key) and which value is a dict composed of
variable matches. variable matches.
""" """
if not self.getWorklistValueList(): worklist_value_list = self.getWorklistValueList()
if not worklist_value_list:
return None return None
portal = self.getPortalObject() portal = self.getPortalObject()
...@@ -397,7 +395,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -397,7 +395,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
security_manager = getSecurityManager() security_manager = getSecurityManager()
workflow_id = self.getId() workflow_id = self.getId()
workflow_title = self.getTitle() workflow_title = self.getTitle()
for worklist_value in self.getWorklistValueList(): for worklist_value in worklist_value_list:
action_box_name = worklist_value.getActionName() action_box_name = worklist_value.getActionName()
is_guarded = worklist_value.isGuarded() is_guarded = worklist_value.isGuarded()
guard_role_list = worklist_value.getGuardRoleList() guard_role_list = worklist_value.getGuardRoleList()
...@@ -623,14 +621,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -623,14 +621,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
state_var = self.getStateVariable() state_var = self.getStateVariable()
status_dict = self.getCurrentStatusDict(document) status_dict = self.getCurrentStatusDict(document)
current_state_value = self._getWorkflowStateOf(document, id_only=0) current_state_value = self._getWorkflowStateOf(document, id_only=0)
source_value = self.getSourceValue()
if current_state_value == None: if current_state_value == None:
current_state_value = self.getSourceValue() current_state_value = source_value
old_state = current_state_value.getReference() old_state = current_state_value.getReference()
old_sdef = current_state_value old_sdef = current_state_value
if tdef is None: if tdef is None:
new_sdef = self.getSourceValue() new_sdef = source_value
new_state = new_sdef.getReference() new_state = new_sdef.getReference()
if not new_sdef: if not new_sdef:
...@@ -675,7 +673,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -675,7 +673,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# update variables # update variables
state_values = None state_values = None
# seems state variable is not used in new workflow. # seems state variable is not used in new workflow.
object = self.getStateChangeInformation(document, self.getSourceValue()) object = self.getStateChangeInformation(document, source_value)
if new_sdef is not None: if new_sdef is not None:
state_values = getattr(new_sdef,'var_values', None) state_values = getattr(new_sdef,'var_values', None)
if state_values is None: if state_values is None:
...@@ -840,8 +838,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -840,8 +838,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = tuple(self.getProperty('workflow_managed_permission')) value = tuple(self.getProperty('workflow_managed_permission'))
prop_type = self.getPropertyType('workflow_managed_permission') prop_type = self.getPropertyType('workflow_managed_permission')
elif prop_id == 'initial_state': elif prop_id == 'initial_state':
if self.getSourceValue() is not None: source_value = self.getSourceValue()
value = self.getSourceValue().getReference() if source_value is not None:
value = source_value.getReference()
else: else:
value = '' value = ''
prop_type = 'string' prop_type = 'string'
...@@ -974,8 +973,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -974,8 +973,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sub_object = SubElement(variable, property_id, attrib=dict(type='int')) sub_object = SubElement(variable, property_id, attrib=dict(type='int'))
elif property_id == 'variable_value': elif property_id == 'variable_value':
property_value = vdef.getVariableValue() property_value = vdef.getVariableValue()
if vdef.getVariableValue() is not None:
property_value = vdef.getVariableValue()
sub_object = SubElement(variable, property_id, attrib=dict(type='string')) sub_object = SubElement(variable, property_id, attrib=dict(type='string'))
else: else:
property_value = vdef.getProperty(property_id) property_value = vdef.getProperty(property_id)
...@@ -1107,7 +1104,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1107,7 +1104,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
tdef_exprs = {} tdef_exprs = {}
status = {} status = {}
for id, vdef in self.getVariableValueDict().items(): for id, vdef in state_values.items():
if not vdef.getStatusIncluded(): if not vdef.getStatusIncluded():
continue continue
expr = None expr = None
...@@ -1184,9 +1181,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -1184,9 +1181,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = variable_expression(ec) value = variable_expression(ec)
else: else:
value = variable.getVariableValue() value = variable.getVariableValue()
if hasattr(self, 'getSourceValue'): source_value = self.getSourceValue()
if self.getSourceValue() is not None: if source_value is not None:
initial_state = self.getSourceValue().getReference() initial_state = source_value.getReference()
if state_var is not None: if state_var is not None:
res[state_var] = status.get(state_var, initial_state) res[state_var] = status.get(state_var, initial_state)
return res return res
......
...@@ -162,9 +162,11 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject, ...@@ -162,9 +162,11 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
elif id == 'simulation_state': elif id == 'simulation_state':
matches_id_list = self.getMatchedSimulationStateList() matches_id_list = self.getMatchedSimulationStateList()
# Get workflow state's reference: # Get workflow state's reference:
parent = self.getParent()
for state_id in matches_id_list: for state_id in matches_id_list:
if hasattr(self.getParent(), state_id): state = getattr(parent, state_id, None)
matches_ref_list.append(self.getParent()._getOb(state_id).getReference()) if state is not None:
matches_ref_list.append(state.getReference())
else: matches_ref_list = matches_id_list else: matches_ref_list = matches_id_list
matches = tuple(matches_ref_list) matches = tuple(matches_ref_list)
elif id == 'causality_state': elif id == 'causality_state':
...@@ -174,8 +176,9 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject, ...@@ -174,8 +176,9 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
elif id: elif id:
# Local dynamic variable: # Local dynamic variable:
dynamic_variable = self._getOb('variable_'+id) dynamic_variable = self._getOb('variable_'+id)
if dynamic_variable.getVariableValue(): dynamic_variable_value = dynamic_variable.getVariableValue()
matches = [dynamic_variable.getVariableValue()] if dynamic_variable_value:
matches = [dynamic_variable_value]
# Override initial value if expression set: # Override initial value if expression set:
dynamic_variable_expression_text = dynamic_variable\ dynamic_variable_expression_text = dynamic_variable\
.getVariableExpression() .getVariableExpression()
......
...@@ -229,13 +229,17 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -229,13 +229,17 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
else: else:
portal_type = None portal_type = None
# Workflow assignment: portal_type_workflow_list = tuple()
if portal_type is not None: if portal_type is not None:
for workflow_id in portal_type.getTypeWorkflowList(): portal_type_workflow_list = portal_type.getTypeWorkflowList()
# Workflow assignment:
for workflow_id in portal_type_workflow_list:
workflow_list.append(self._getOb(workflow_id)) workflow_list.append(self._getOb(workflow_id))
# DCWorkflow assignment # DCWorkflow assignment
for wf_id in self.getChainFor(ob): for wf_id in self.getChainFor(ob):
if portal_type is not None and wf_id in portal_type.getTypeWorkflowList(): if wf_id in portal_type_workflow_list:
continue continue
wf = self.getWorkflowById(wf_id) wf = self.getWorkflowById(wf_id)
if wf is not None: if wf is not None:
...@@ -248,8 +252,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -248,8 +252,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
""" Get the history of an object for a given workflow. """ Get the history of an object for a given workflow.
""" """
if hasattr(aq_base(ob), 'workflow_history'): if hasattr(aq_base(ob), 'workflow_history'):
wfh = ob.workflow_history return ob.workflow_history.get(wf_id, None)
return wfh.get(wf_id, None)
return () return ()
def _encodeWorkflowUid(self, id): def _encodeWorkflowUid(self, id):
......
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