Problem/Motivation

Background: in doing a performance audit for a site with groups module installed, I noticed that their main menu block had several group_relationship_list cache tags on it - the menu almost entirely contains links to nodes. This means the menu block (and dynamic page cache) is added whenever a group relationship is created for any node.

group_entity_access() has the following code:

  // If any new relationship entity is added using any of the retrieved
  // plugins, it might change access.
  $plugin_cache_tags = [];
  foreach ($plugin_ids as $plugin_id) {
    $plugin_cache_tags[] = "group_relationship_list:plugin:$plugin_id";
  }
  $access = AccessResult::neutral()->addCacheTags($plugin_cache_tags);

When saving a relationship for an entity, the cache tags for the entity itself are invalidated, this is also the case after #2872697: Stop saving an entity when it gets added to or removed from a group.

Given that, I think it should be OK to remove the list cache tags from group_entity_access() entirely, and rely on the invalidation of the entity cache tag instead. This would dramatically improve render cache hit rates on some sites if it's possible.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork group-3538509

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

catch created an issue. See original summary.

kristiaanvandeneynde’s picture

One thing I just realized by reading this IS, is that #2872697: Stop saving an entity when it gets added to or removed from a group did not add list cache tags to its solution.

So if you had a list of 5 nodes you had access to due to how they were grouped and you lose that access, we are fine because the list was tagged with both the individual nodes' cache tags and node_list. However, if you gain access because a node got added to one of your groups, the list won't show it because we no longer invalidate list cache tags.

Edit: We might not be fine, EntityListBuilder for instance only uses list cache tags. I can post this publicly as v4 isn't out yet. But we definitely need to fix that before release.


Now, to the issue at hand, hook_entity_access() does not apply to lists, so the facepalm I just had should not get worse if we do as the IS suggests. And as you mentioned, adding or removing an entity from a group will either save the entity (v2/v3) or invalidate its tags (v4). So a main menu block should always get updated when one of the nodes that are actually in the menu have their group status changed.

So I think you're right and we can completely remove that piece of code.

catch’s picture

Status: Active » Needs review

Put an MR up.