Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Action includes always get loaded using the slow file_scan_directory() in views_bulk_operations_init(), even if VBO is not used on current page.
With views_bulk_operations_action_info() and views_bulk_operations_theme() loading the files (which already seems too much), why is it needed to do another pass loading the includes on hook_init()?
In any case there should be a function with static cache to keep track of whether each file is loaded or not before trying for an expensive file_scan_directory() call.
Comment | File | Size | Author |
---|---|---|---|
#8 | vbo_load_actions_init-1235736-8.patch | 1.42 KB | hefox |
#5 | 1235736.patch | 3.18 KB | bojanz |
#1 | patch_commit_983966f239ec.patch | 2.99 KB | moonray |
Comments
Comment #1
moonray CreditAttribution: moonray commentedAnd here's a patch.
If there is a god reason to keep loading the action includes in hook_init, let me know. It should probably be documented in code, at that point.
Comment #2
bojanz CreditAttribution: bojanz commentedWhat we are doing right now is insane, and your patch is almost perfect in fixing it.
There is no need to do the including in hook_init(). Doing it in our implementation of hook_action_info() is enough because that hook is invoked both when an action is executed (by actions_do()) and when actions are listed in VBO / views admin (because views_bulk_operations_operation_action_list() calls actions_list() which invokes hook_action_info).
The only thing I'd add to your patch is caching (indefinitely) the output of file_scan_directory(). Even with the patch it is guaranteed that file_scan_directory() will be invoked once per (vbo / action execution) request, all in order to scan a directory whose list of files doesn't really change. Having to do a cache clear after adding a new action file (which I guess will happen three to four times during the whole D7 cycle) is perfectly fine.
Comment #3
moonray CreditAttribution: moonray commentedI ran some (admittedly local) speed tests, and DB reading seemed to be slower than reading the file dir. Of course, it's a small dir.
I had written the caching code, but stripped it when I saw that it was slower.
Thoughts?
Comment #4
bojanz CreditAttribution: bojanz commentedI spoke to catch about this. His conclusion:
Hardcoding the list of files > variable_get > cache > file_scan_directory().
And I'm fine with just hardcoding the list in an array at the top of views_bulk_operations_load_includes() (though we might want to rename it to views_bulk_operations_load_actions or views_bulk_operations_load_action_includes), along with a comment explaining the situation.
Comment #5
bojanz CreditAttribution: bojanz commentedSo, how about this? Works on my setup.
Comment #6
bojanz CreditAttribution: bojanz commentedCommitted.
Comment #8
hefox CreditAttribution: hefox commentedSemi-backport for d6. The functions are a bit different so did what seemed relavent
Comment #9
jonhattanMeasured ~1.4ms less in hook_init
Comment #10
kenorb CreditAttribution: kenorb commentedFixed in 7.x as per #6. Since D6 is no longer supported, therefore backported patch most likely won't be applied anymore.