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.

Comments

kadet1090 created an issue. See original summary.

larowlan’s picture

Category: Bug report » Feature request
Issue tags: -cache, -menu

I 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.

larowlan’s picture

Actually, 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.

kadet1090’s picture

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.

Could you maybe share how you do this, this would be really useful workaround for now, because my only idea was to patch this out.

nterbogt’s picture

Assigned: Unassigned » nterbogt
Status: Active » Needs work
StatusFileSize
new5.43 KB

Here 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.

larowlan’s picture

+++ b/modules/entity_hierarchy_microsite/src/Entity/Microsite.php
@@ -123,6 +137,13 @@ class Microsite extends ContentEntityBase implements MicrositeInterface {
+  public function shouldGenerateMenu() {

+++ b/modules/entity_hierarchy_microsite/src/Entity/MicrositeInterface.php
@@ -25,4 +25,12 @@ interface MicrositeInterface extends ContentEntityInterface {
+  public function shouldGenerateMenu();

Let's add a :bool return type hint here

I also believe we no longer need the override content entity and it can be done with core

- 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.

larowlan’s picture

Status: Needs work » Needs review
Issue tags: +Needs update path

Marking needs review for the sake of the bot

We'll need an update hook here to add the new field

larowlan’s picture

Category: Feature request » Bug report

This is also a bug now

Status: Needs review » Needs work

The last submitted patch, 5: entity_hierarchy-opt_in_menu-3284026-5.patch, failed testing. View results

nterbogt’s picture

StatusFileSize
new6.9 KB

Including my forgotten update hook.
Updating with the boolean typehint.

larowlan’s picture

Assigned: nterbogt » larowlan

Picking this up

larowlan’s picture

Status: Needs work » Needs review
Issue tags: -Needs update path
StatusFileSize
new8.08 KB
new14.23 KB

Test fixes

One test caught we lost the protection against exceeding max depth of 9, so added in new code for that.

larowlan’s picture

StatusFileSize
new100.85 KB
new114.43 KB

And with an update path test

larowlan’s picture

Assigned: larowlan » Unassigned
larowlan’s picture

StatusFileSize
new163.62 KB
new117.76 KB

Additional update path to mark all old items as discovered so they should be cleaned up if the content is no longer in the tree

larowlan’s picture

StatusFileSize
new4.62 KB
new116.01 KB

Some changes identified by @nterbogt

  • larowlan committed 9d31bbf on 3.x
    Issue #3284026 by larowlan, nterbogt: Menu Link Discovery takes forever...
larowlan’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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