Commit 32d0382e authored by iv's avatar iv

ERP5Workflow: PERF: avoid compilation of expression being done again and again

parent 9a61b162
......@@ -147,7 +147,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
# Not set yet. Use a default.
elif variable_expression is not None:
ec = createExprContext(StateChangeInfo(ob, self, status))
value = Expression(variable_expression)(ec)
value = variable_expression(ec)
else:
value = vdef.getVariableValue()
......@@ -289,7 +289,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
else:
variable_expression = vdef.getVariableExpression()
if variable_expression is not None:
expression = Expression(variable_expression)
expression = variable_expression
else:
value = vdef.getVariableValue()
if expression is not None:
......
......@@ -481,7 +481,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# Not set yet. Use a default.
elif variable_expression is not None:
ec = createExprContext(StateChangeInfo(ob, self, status))
value = Expression(variable_expression)(ec)
value = variable_expression(ec)
else:
value = vdef.getVariableValue()
......@@ -715,7 +715,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
expr = variable_expression
else:
value = vdef.getVariableValue(object=object)
if expr not in(None, ''):
if expr not in (None, ''):
# Evaluate an expression.
if econtext is None:
# Lazily create the expression context.
......@@ -725,7 +725,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
document, self, former_status, tdef,
old_sdef, new_sdef, kwargs)
econtext = createExprContext(sci)
expr = Expression(expr)
value = expr(econtext)
status_dict[variable_reference] = value
# Do not proceed in case of failure of before script
......@@ -949,7 +948,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for tr_var in tr_var_list:
reference = self._getOb(tr_var.getCausalityId()).getReference()
transition_variable = SubElement(transition_variables, property_id, attrib=dict(id=reference,type='variable'))
transition_variable.text = str(tr_var.getVariableExpression())
transition_variable.text = str(tr_var.getVariableExpressionText())
else:
property_value = tdef.getProperty(property_id)
property_type = tdef.getPropertyType(property_id)
......@@ -1123,7 +1122,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
else:
variable_expression = vdef.getVariableExpression()
if variable_expression is not None:
expr = Expression(variable_expression)
expr = variable_expression
else:
value = vdef.getVariableValue()
if expr is not None:
......@@ -1183,7 +1182,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
elif variable_expression is not None:
ec = createExprContext(StateChangeInfo(ob, self, status))
# convert string to expression before execute it.
value = Expression(variable_expression)(ec)
value = variable_expression(ec)
else:
value = variable.getVariableValue()
if hasattr(self, 'getSourceValue'):
......
......@@ -35,7 +35,7 @@ from Products.ERP5Type.XMLObject import XMLObject
class WorkflowVariable(IdAsReferenceMixin("variable_", "prefix"), XMLObject):
"""
A ERP5 Variable.
A ERP5 Workflow Variable.
"""
meta_type = 'ERP5 Variable'
......@@ -65,6 +65,15 @@ class WorkflowVariable(IdAsReferenceMixin("variable_", "prefix"), XMLObject):
PropertySheet.WorkflowVariable,
)
def _setVariableExpression(self, expression):
if isinstance(expression, Expression):
self.variable_expression = Expression(expression.text)
else:
self.variable_expression = Expression(expression)
def getVariableExpressionText(self):
return getattr(self.variable_expression, 'text', '')
def getInfoGuard(self):
if self.getGuardRoleList() is None and\
self.getGuardPermissionList() is None and\
......@@ -73,7 +82,7 @@ class WorkflowVariable(IdAsReferenceMixin("variable_", "prefix"), XMLObject):
self.info_guard is None:
return Guard().__of__(self)
elif self.info_guard is None:
self.generateGuard()
self.generateInfoGuard()
return self.info_guard
def generateInfoGuard(self):
......
......@@ -177,10 +177,12 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject,
if dynamic_variable.getVariableValue():
matches = [dynamic_variable.getVariableValue()]
# Override initial value if expression set:
if dynamic_variable.getVariableExpression():
matches = Expression(dynamic_variable.getVariableExpression())
dynamic_variable_expression_text = dynamic_variable\
.getVariableExpression()
if dynamic_variable_expression_text:
matches = dynamic_variable_expression_text
if matches is not [] and matches is not None:
if matches not in ([], None):
if not isinstance(matches, (tuple, Expression)):
# Old version, convert it.
matches = tuple(matches)
......
......@@ -461,7 +461,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
worklist_variable_value = worklist.newContent(portal_type='Worklist Variable',
reference=key)
if isinstance(values, Expression):
worklist_variable_value.setVariableExpression(values.text)
worklist_variable_value.setVariableExpression(values)
else:
worklist_variable_value.setVariableValue(values[0]) #XXX(WORKFLOW): to be changed
......@@ -537,9 +537,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# for a very specific case, action return the reference of transition
# in order to generation correct workflow history.
if variable_id == 'action':
variable.setVariableExpression('transition/getReference|nothing')
variable.setVariableExpression(Expression('transition/getReference|nothing'))
else:
variable.setVariableExpression(variable_definition.default_expr.text)
variable.setVariableExpression(variable_definition.default_expr)
if variable_definition.info_guard:
variable.info_guard = variable_definition.info_guard
variable.setGuardRoleList(variable_definition.info_guard.roles)
......@@ -565,7 +565,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
else: var_exprs = origin_tdef.var_exprs
for key in var_exprs:
tr_var = transition.newContent(portal_type='Transition Variable', temp_object=is_temporary)
tr_var.setVariableExpression(var_exprs[key].text)
tr_var.setVariableExpression(var_exprs[key])
tr_var_path = getattr(workflow, 'variable_'+key).getPath()
tr_var_path = '/'.join(tr_var_path.split('/')[2:])
new_category.append(tr_var_path)
......@@ -582,7 +582,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
else: var_exprs = origin_tdef.var_exprs
for key in var_exprs:
tr_var = interaction.newContent(portal_type='Transition Variable', temp_object=is_temporary)
tr_var.setVariableExpression(var_exprs[key].text)
tr_var.setVariableExpression(var_exprs[key])
tr_var_path = getattr(workflow, 'variable_'+key).getPath()
tr_var_path = '/'.join(tr_var_path.split('/')[2:])
new_category.append(tr_var_path)
......
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