Problem/Motivation

This is really only a serious problem on sites with mega menus and frequent content edits, but is somewhere between a real and a theoretical problem for almost any site.

Whenever a node *with* a menu item edited via the node form addition from menu_ui module is saved, the MenuLinkContent item is saved regardless of if there is any changes.

MenuLinkContent::postSave() calls MenuLinkManager:: updateDefinition() or addDefinition() which then call MenuTreeStorage::save which calls:

```
$cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
$this->cacheTagsInvalidator->invalidateTags($cache_tags);
```

On a site with a few hundred main menu links that can lead to excessive cache churn both locally and within CDN depending on configurations/contrib module.

In total this clears the following cache tags:
If a *draft*:
* "menu_link_content_list"
* "menu_link_content_list:menu_link_content"
* "4xx-response" (probably a second time -- this is cleared by the node save as well)
* "menu_link_content:ID"

If published:
* All the previous ones
* "menu_link_content:ID:revisions"
* "config:system.menu.MENU_ID"

Steps to reproduce

  • Add a node to a menu via the node menu form
  • Save the node as published
  • Edit the node, make no changes and save
  • Confirm cache tags cleared (personally I just sat xdebug in CacheTagsInvalidator::invalidateTags())

Proposed resolution

Add checks if there are any changes in values and don't save if there are no changes.

Remaining tasks

Are tests required for this change -- I think current test are adequate for ensuring real changes go through. Do we need tests for the cache change?

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

None

Issue fork drupal-3621456

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

nickdickinsonwilde created an issue. See original summary.

nickdickinsonwilde’s picture

Status: Active » Closed (duplicate)
Related issues: +#3485030: Avoid saving menu links through node form when they do not change

bah. When I went to make the change, I found it was already done but not tagged as menu_ui.module in the issue queue so didn't find any cache issues when I searched there. #3485030: Avoid saving menu links through node form when they do not change

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.