Problem/Motivation
When a node is saved the menu UI module re-saves the menu link content, irrespective of whether its changed, this looks to be by design, the menu tree storage save then in turn clears the caches of all affected menus.
In the event that the menu link has not changed the menu tree storage still stores the current link item as an affected menu, which then in turn gets cleared from the cache.
Steps to reproduce
- Edit a node with a menu link.
- The menu link content will be updated
- The menu cache will be invalidated
Proposed resolution
Change the doSave method so it returns no affected menus if no menus would be affected by the save.
See https://www.drupal.org/project/drupal/issues/2302137#comment-12070772 and https://www.drupal.org/project/drupal/issues/2876343 for more background
| Comment | File | Size | Author |
|---|
Issue fork drupal-3486604
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
andy_w commentedComment #3
andy_w commentedIts worth mentioning that menu link weight has a similar patch for a very similar observation,
Comment #4
cilefen commentedThe test bots don't test patches any more. Please would you open a merge request?
Comment #7
godotislateI have a suggestion for a simpler change that might work.
MR also needs tests.
Comment #8
andy_w commentedAs I understand it $entity->hasTranslationChanges() will only give us the output we are after if the menu is setup to use translation, which is why I wrote it off in the first place (though I could be wrong, and hope I am, as it would be a much nicer solution).
Comment #9
godotislateOn a standard profile install, hasTranslationChanges() detects changes on the entity without content translation enabled.
Comment #13
andy_w commentedThe actual issue here appears to stem from the fact that the doSave method on menu tree storage still returns the current menu even if no changes were detected - causing an unnecessary cache clear.
The code suggests an exit early state but it still returns with the current menu, causing follow on actions.
Comment #15
andy_w commentedComment #16
andy_w commentedIt would appear that this was flagged as a follow up action many years https://www.drupal.org/project/drupal/issues/2302137#comment-12070910 and further discussed here: https://www.drupal.org/project/drupal/issues/2876343
However this has a significant impact upon a sites performance if every time an editor saves a page in the menu system (without making a change to the menu) the whole site is essentially cleared from the cache.
Comment #17
andy_w commentedMy assumption is that the failing tests (in unrelated aspects of the system) are based on the fact that they require a cache clear and are relying on an incidental cache clear to occur based on this change.
Comment #18
andy_w commentedComment #19
andy_w commentedComment #20
dmitry.korhov@andy_w, shall we close this one and focus on https://www.drupal.org/project/drupal/issues/3485030 instead?
Comment #21
andy_w commentedI agree @dmitry.korhov
Closed as duplicate of https://www.drupal.org/project/drupal/issues/3485030