Problem/Motivation

\Drupal\group\Entity\GroupContent::getCacheTagsToInvalidate defines a whole bunch of list cache tags for various use cases. They are useful, but they are in the wrong place.

getCacheTagsToInvalidate() is also called from getCacheTags(), which mean that if you do ->addCacheableDependency($group), then all these list cache tags are also added to that element, but you didn't ask for cache tags for what happens when any content in that group changes, just that specific group.

The naming of those methods is a bit unfortunate and this isn't clear. This also caused a lot of confusing in the recently committed bundle cache tag issue in core: #2145751: Introduce ENTITY_TYPE_list:BUNDLE cache tag and add it to single bundle listing.

Proposed resolution

Luckily, that core issue also gives us exactly what we need here, a new method getListCacheTagsToInvalidate() that we can override. Unlike the other method, this one is _only_ used for invalidation, and it is up to each implementation of a list to pick the correct cache tag. Which is most likely only one, for example you only want to invalidate content of group A XOR everything of the plugin X. Not all possible things that the group module supports to invalidate.

This also means that this patch requires #3088226: Remove deprecations, compatibility with Drupal 9 and won't work on 8.7.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 group-list-cache-tags-3110773-2.patch1.49 KBberdir

Comments

Berdir created an issue. See original summary.

berdir’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new1.49 KB

The test still passes because you only test invaidation not how cache tags are added. Might want to do that as well somewhere in a functional test when looking at group/1, but these things also tend to break easily if core adds/removes some cache tags on the default output due to core changes.

Status: Needs review » Needs work

The last submitted patch, 2: group-list-cache-tags-3110773-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Status: Needs work » Needs review

Failed as expected on 8.7.

berdir’s picture

Also failed on 8.8, passed now on 8.9, forgot that the bundle list cache tag issue is only in 8.9.

You might want to hold out a bit with this, but this is a pretty severe performance issue.

kristiaanvandeneynde’s picture

Issue tags: +Group 8.1 target

I'll add it to the 8.1 release, at which time it should be safe to bump up the core version requirement.

kristiaanvandeneynde’s picture

Issue tags: -Group 8.1 target +Group 8.2 target

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Committed, thanks!

Re #3: Might need to do a follow-up for that. Currently a bit stretched on time.
Will bump core version to 8.9, but doing so in a separate ticket so it makes it into the release notes.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.