Problem/Motivation
Recently in debugging the performance and page load of a site under development i noticed that workflow_get_workflow_node_by_nid(), workflow_get_workflow_type_map_by_type(), and workflow_get_workflow_scheduled_transition_by_nid() were all being called 281 times on a pretty simple (for our site) page view.
After tracking this down i found the culprit to be workflow_node_load. This function attempts to load the current workflow node state for all of the $nodes values passed into it regardless if that node type even has an attached workflow.
Proposed resolution
I've created a patch that attempts to address this issue. This patch builds an array of valid node (content) types by calling workflow_get_workflow_type_map() and filtering out only those types that have a valid WID. Then before loading the workflow information we check the current node against the matching valid node types
On the site I'm developing this reduced the number of SQL calls from 1288, to 493 since we only have workflows attached to certain types.
Remaining tasks
I'm not sure that this patch is necessarily coded in the same style of the module, and would appreciate any style changes that may be necessary
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | workflow-hook_node_load_performance-1484126-1.patch | 2.23 KB | nathangervais |
Comments
Comment #1
nathangervais commentedAttaching patch.
Comment #2
joel_osc commentedThanks, the patch worked great...would be nice if it hit latest dev soon.
Comment #3
nancydruThanks for the patch. I would have noticed it much sooner if you had marked it "Needs review."
Given that I've done some work on this function, this patch won't apply, but may not be needed any longer.
Comment #4
nancydruUsing your idea, I reworked the code.