This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
Do not invalidate group content list cache tags when the group itself changes #509
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is resulting out of an exception which has been thrown in one of the tests in my project while using the latest 8.x-1.x branch of OG (ref. https://app.continuousphp.com/git-hub/ec-europa/joinup-dev/build/074b4465-414f-41b1-8cf1-4a186270c5e7/logs/e70792da-5a92-42da-be11-d58a857d1fd3).
In #499 we added an exception to detect cases where
MembershipManager::getGroupIds()
is being called on entities which are not groups, which is an invalid use case. It turns out we have a case inog_invalidate_group_content_cache_tags()
where this happens.The purpose of this function is to invalidate cached listings of group content whenever group content changes. When this function was originally written the idea was also to invalidate group content listings when the group itself changes. This was probably considered since it is common for a group content listing to include the group label itself (a typical example is the
RecentGroupContentBlock
).Now this intended functionality seems to have been broken for a long time. There were some checks to see if the passed in entity is a group that has recently changed, but nothing is then done with this inside the function.
Now the reason this still works as expected is because we do not actually need to invalidate the listing's cache tags if the group itself changes. It is only needed when group content changes. If the listing would include any data from the group itself (such as the label), then the cache tags of the group will also be attached to the listing, and it will be invalidated automatically when the group is saved. For an example of this mechanism in action check
EntityReferenceLabelFormatter::viewElements()
which will attach the cache tags of the referenced group if this label is shown.I have created a test that demonstrates the circumstances where the exception occurs, and some additional test coverage that asserts the content listings will only be invalidated when the group's cache tags are present.