It is a very big performance hit that, whenever a View is saved, the menu_cache is rebuilt:

In view.inc->save()

    // Clear caches.
    views_invalidate_cache();

Wich at the same time calls:

function views_invalidate_cache() {
  // Clear the views cache.
  cache_clear_all('*', 'cache_views', TRUE);

  // Clear the page and block cache.
  cache_clear_all();

  // Set the menu as needed to be rebuilt.
  variable_set('menu_rebuild_needed', TRUE);

  // Allow modules to respond to the Views cache being cleared.
  module_invoke_all('views_invalidate_cache');
}

This cache clearing is overkill.... I mean... we are saving a single view, yet we are:

- Clearing the complete cache_views
- Clearing all page and block cache
- Rebuilding the whole menu!! (can be extremely heavy as this is thone inmediately on the same request)
- Telling other modules that the cache has been invalidated

For now, I just commented out:

variable_set('menu_rebuild_needed', TRUE);

because it only makes sense when any path related configuration of the view has changed. In those cases I just clear the menu cache manually.

¿Would it be feasible to implement a cache clear that is specific for the vew being saved? In that case:

- Only clear the cache_views related to the view being saved.
- Clearing page and block cache: page cache I understand because it is high level caching, but block cache can be a little bit more selective...
- Rebuilding de menu only if menu related changes have been made to the view.
- Don't know about the last item...

Comments

b_sharpe’s picture

+1

Menu rebuild murders me and times out every view save.

andyg5000’s picture

Status: Needs work » Closed (duplicate)

Looks like #2071607: Saving a view causes the entire cache to be invalidated is related and has a patch in place. Closing as a dupe of that one.

Anybody’s picture

Status: Closed (duplicate) » Needs work

I'm now opening this because the case with

variable_set('menu_rebuild_needed', TRUE);

is neither solved with a patch in #2071607 nor with #1978176 in our test case on a large site.

I think this has to be addressed by only rebuilding the menu if a menu related views change was made. So for example if there is only a master display this can not have any effect on the menu because it's no page.

It would be to general perhaps to say that only "page" view displays shell call that but to call the rebuild on every view save is just too much.