Problem/Motivation
On large sites with thousands of nodes menu link discovery can take few minutes to finish. On our larges site with around 8000 nodes cache rebuild takes around 11 minutes to finish, and 99% of this time is due to MicrositeMenuLinkDiscovery. This problem is related to fact that drupal is not well suited to work with menus that have so many items, but this module makes such menu automatically.
Steps to reproduce
Create hierarchy with many (~100) microsites with multiple (~50) pages each. Observe cache rebuild time.
Proposed resolution
The first question is if the menu discovery is really needed. For testing purposes I disabled link discovery and marked all records from the module in menu_tree table as non-discovered and I have not noticed any issues.
The second question is if it is possible to move link discovery process to another command so it is not invoked by the cache rebuild process.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 3284026-15.patch | 116.01 KB | larowlan |
| #16 | 3284026-15-interdiff.txt | 4.62 KB | larowlan |
| #15 | 3284026-14.patch | 117.76 KB | larowlan |
| #15 | 3284026-14-interdiff.txt | 163.62 KB | larowlan |
| #13 | 3284026-13.patch | 114.43 KB | larowlan |
Comments
Comment #2
larowlanI think it would be a good idea to make this an opt-in thing via config.
I've got a few sites where I'm nixing the logic via a hook_module_implements_alter to remove this hook from the module.
Comment #3
larowlanActually, I think it would be better to add a flag to the microsite entity 'derive menus' and consult that.
I'll be working on a new client site that will likely need this in the next month, so will try to tackle it as part of that.
Comment #4
kadet1090 commentedCould you maybe share how you do this, this would be really useful workaround for now, because my only idea was to patch this out.
Comment #5
nterbogt commentedHere is my initial run at an 'opt-in' menu building system for microsites.
This still needs to have 'discovered' set against all the menu items (menu_tree table) in the hook_update_N (except the ones with an override content entity).
I also believe we no longer need the override content entity and it can be done with core, but that's a bigger problem that I can work on after this one. That will be enabled by having 'discovered' => 1 on generated menu items.
Comment #6
larowlanLet's add a :bool return type hint here
- that was a deliberate design decision. We want the overrides managed in content and not in configuration. So I don't want to change that behaviour.
Comment #7
larowlanMarking needs review for the sake of the bot
We'll need an update hook here to add the new field
Comment #8
larowlanThis is also a bug now
Comment #10
nterbogt commentedIncluding my forgotten update hook.
Updating with the boolean typehint.
Comment #11
larowlanPicking this up
Comment #12
larowlanTest fixes
One test caught we lost the protection against exceeding max depth of 9, so added in new code for that.
Comment #13
larowlanAnd with an update path test
Comment #14
larowlanComment #15
larowlanAdditional update path to mark all old items as discovered so they should be cleaned up if the content is no longer in the tree
Comment #16
larowlanSome changes identified by @nterbogt
Comment #18
larowlan