Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

MembershipManager still returns a user's memberships after the user is deleted #480

Merged
merged 4 commits into from
Apr 25, 2019

Conversation

pfrenssen
Copy link
Contributor

MembershipManager::getGroupMembershipsByRoleNames() and MembershipManager::getGroupMembershipIdsByRoleNames() still return the memberships of a user from the static cache after a user is deleted.

There are two possible solutions for this:

  • We can call MembershipManager->reset() in OgMembership::delete() just as it is now being done in OgMembership::save().
  • We can replace the internal static $cache property with core's static MemoryBackend cache backend which has full support for cache tag invalidation.

In this PR I am going to explore the second solution. By using MemoryBackend we can add the correct cache tags to each of our cache entries, and they will be invalidated automatically when needed. This should allow us to remove all calls to MembershipManager::reset() and clean up some code that does unnecessary cache clears.

@pfrenssen
Copy link
Contributor Author

Started by adding a failing test, this demonstrates that MembershipManager still returns the memberships of the deleted user.

@pfrenssen pfrenssen force-pushed the invalidate-cache-on-membership-deletion branch from c4c37dd to 5bde52d Compare April 25, 2019 13:46
This ensures that the static cache is correctly invalidated whenever one of
the cached items is updated.
@pfrenssen pfrenssen force-pushed the invalidate-cache-on-membership-deletion branch from 5bde52d to eddd176 Compare April 25, 2019 14:10
@pfrenssen
Copy link
Contributor Author

OK so using the memory backend that supports invalidation based on cache tags fixes the issue without requiring any changes to the code base.

I'm now removing all calls to MembershipManager::reset(). I'm expecting these to be no longer needed.

@pfrenssen pfrenssen force-pushed the invalidate-cache-on-membership-deletion branch from 7614817 to 739ec60 Compare April 25, 2019 14:48
It is no longer needed. The service is now using a cache backend that gets
cleared automatically whenever related cache tags are invalidated.
@pfrenssen pfrenssen force-pushed the invalidate-cache-on-membership-deletion branch from 739ec60 to d6baff9 Compare April 25, 2019 15:12
@pfrenssen
Copy link
Contributor Author

Great! Working fine, and the bug is fixed :)

src/MembershipManager.php Show resolved Hide resolved
@pfrenssen pfrenssen merged commit a68f578 into 8.x-1.x Apr 25, 2019
@pfrenssen pfrenssen deleted the invalidate-cache-on-membership-deletion branch April 25, 2019 19:29
*/
protected $cache;
protected $staticCache;
Copy link
Collaborator

@claudiu-cristea claudiu-cristea May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfrenssen, I wonder why we're only doing memory caching here. This looks to me a good candidate to double the memory caching with persistent caching (database, Redis, etc.). All we need here is to declare a \Drupal\Core\Cache\BackendChain service and add a memory and a cache bin backends to it. Then replace the static cache service with this one. That would improve dramatically the performance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #485 to fix this.

/**
* {@inheritdoc}
*/
public function reset() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, This should have been deprecated instead of fully removed. I know we're not offering yet BC but still, given the fact that so many sites are already using OG...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, we could have deprecated this.
It broke tests in #181.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants