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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willzyx created an issue. See original summary.

willzyx’s picture

Status: Active » Needs review
FileSize
1.08 KB

The attached patch makes WorkflowItem::getAllowedValues() load only the relevant states for the workflow associated to the field

willzyx’s picture

FileSize
118.59 KB

quick 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

  • johnv committed 8188229 on 7.x-2.x authored by willzyx
    Issue #2913092 by willzyx: [Performance] Load only relevant states in...
johnv’s picture

Version: 7.x-2.x-dev » 7.x-2.10
Status: Needs review » Fixed

You are correct. Fixed.

johnv’s picture

I have checked the relevant code in D8. That seems OK.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.