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

  1. Edit a node with a menu link.
  2. The menu link content will be updated
  3. 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

Issue fork drupal-3486604

Command icon 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

andy_w created an issue. See original summary.

andy_w’s picture

Assigned: andy_w » Unassigned
Status: Active » Needs review
andy_w’s picture

Its worth mentioning that menu link weight has a similar patch for a very similar observation,

cilefen’s picture

Version: 10.3.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: +Needs merge request

The test bots don't test patches any more. Please would you open a merge request?

atul_ghate made their first commit to this issue’s fork.

godotislate’s picture

I have a suggestion for a simpler change that might work.

MR also needs tests.

andy_w’s picture

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

godotislate’s picture

On a standard profile install, hasTranslationChanges() detects changes on the entity without content translation enabled.

andy_w changed the visibility of the branch 3486604-node-edit-form to hidden.

andy_w’s picture

Title: Node edit form re-saves menu items even if no change has occurred » Menu caches are cleared on save method of menu tree storage even if it detects no changes
Status: Needs work » Needs review

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

andy_w changed the visibility of the branch 3486604 to hidden.

andy_w’s picture

andy_w’s picture

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

andy_w’s picture

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

andy_w’s picture

Issue summary: View changes
andy_w’s picture

dmitry.korhov’s picture

Status: Needs review » Needs work

@andy_w, shall we close this one and focus on https://www.drupal.org/project/drupal/issues/3485030 instead?

andy_w’s picture

Status: Needs work » Closed (duplicate)

I agree @dmitry.korhov

Closed as duplicate of https://www.drupal.org/project/drupal/issues/3485030