I noticed that the WorkflowItem::getAllowedValues()
method in workflow field module loads a large amount of objects, (apparently) without a good reason, slowing down the page execution. On a system with some workflows and a large amount of states/transitions this can cause performance issues
public function getAllowedValues() {
// Get all state names, including inactive states.
$options = workflow_get_workflow_state_names(0, $grouped = FALSE, $all = TRUE);
return $options;
}
the above code load ALL the Workflow entities, ALL the WorkflowState entities and ALL the WorkflowConfigTransition entities present on the system for provide the allowed values for a single workflow field (which of course can be associated with only one Workflow).
The method docblock states: It contains all possible values, because the result is cached, and used for all nodes on a page.
; but since the allowed values are statically cached on a field basis and a field can be associated with only one Workflow there is no need to load all these objects... I'm missing something?
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#3 | workflow_after_patch.png | 118.59 KB | willzyx |
#2 | performance_load_only-2913092-2.patch | 1.08 KB | willzyx |
Comments
Comment #2
willzyx CreditAttribution: willzyx commentedThe attached patch makes WorkflowItem::getAllowedValues() load only the relevant states for the workflow associated to the field
Comment #3
willzyx CreditAttribution: willzyx commentedquick profiling with patch in 2
- php PHP 7.0.22-0ubuntu0.17.04.1
- clean site with 2 workflows and 10 states (totally, 5 each)
- view a node with a workflow field
Comment #5
johnvYou are correct. Fixed.
Comment #6
johnvI have checked the relevant code in D8. That seems OK.