Skip to:
Content

BuddyPress.org

Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#9000 closed defect (bug) (fixed)

Group member object cache not refreshed after removal

Reported by: iandunn's profile iandunn Owned by: imath's profile imath
Milestone: 12.0.0 Priority: normal
Severity: normal Version:
Component: Groups Keywords: has-patch commit
Cc:

Description

If you're using memcached and remove a member from a group, the corresponding cached value isn't cleared in all of the places where it's fetched.

Environment setup

  1. Core trunk @ 89da2ff3a9
  2. BuddyPress 11.3.1
  3. memcached plugin. No other plugins active.
  4. twentytwentythree theme
  5. memcached server
  6. memcache (no d) PHP extension
  7. Create a group with ID 1
  8. Create a user with ID 2

Reproduce bug

  1. wp bp group member list 1. Only shows user 1. User 2 is not listed
  2. wp bp group list --user-id=2. Shows no memberships
  1. wp bp group member add --group-id=1 --user-id=2. Shows success
  2. wp bp group list --user-id=2. Shows the membership is assigned
  3. wp bp group member list 1. User 2 is listed
  1. wp bp group member remove --group-id=1 --user-id=2. Shows success.
  2. wp bp group member list 1. User 2 not listed
  3. wp bp group list --user-id=2

group member list is correct, but group list --user-id still has the cached value from before the removal. If you check the wp_bp_groups_members table, you'll see that the membership was removed.

  1. Run flush_all in memcached telnet
  2. wp bp group list --user-id=2

Now it correctly shows no memberships.

If you disable the memcached plugin and repeat steps, you'll get the correct results. So the bug is limited to memcached.

I encountered this when debugging some web code, so it's not limited to the WP-CLI commands, I just used those above to make reproduction simpler.

Attachments (1)

9000.unittests.patch (1.9 KB) - added by imath 11 months ago.

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in PR #171 on buddypress/buddypress by @iandunn.


11 months ago
#1

  • Keywords has-patch added

The groups_remove_member action triggers groups_clear_group_user_object_cache(), but that doesn't clear the cache set in BP_Groups_Group::get().

An extra action was added to reset the bp_groups cache incrementor when a member is removed.

#2 @imath
11 months ago

  • Milestone changed from Awaiting Review to 12.0.0

Hello @iandunn ☺️,

Thanks a lot for your report and patch 👍. Patch looks great. I’ll look at it more deeply asap.

#3 @imath
11 months ago

This is really weird, according to unit tests cache seems to be cleared.

If this is specific to memcached, could you also test when a member leaves the group ? I'm afraid as the fired hook in this case is different groups_leave_group() or BP_Groups_Member::delete() might also miss clearing memcached cache.

@espellcaste is the "leave" command missing in https://github.com/buddypress/wp-cli-buddypress/blob/master/src/group-member.php ?

Last edited 11 months ago by imath (previous) (diff)

#4 @iandunn
11 months ago

I didn't spend much time testing transients, but when I did I wasn't able to reproduce it. I could only reproduce it while using memcache.

Thanks for pointing out those additional cases, I'll test them 👍🏻

#5 @iandunn
11 months ago

It looks like memcache does gets cleared from groups_leave_group() 👍🏻 I'm guessing by this:

https://github.com/buddypress/buddypress/blob/14735fd5c1607b6ee99bbadf36b73e9f406b1d78/src/bp-groups/bp-groups-cache.php#L180

#6 @imath
11 months ago

  • Keywords commit added

Thanks a lot for your checks @iandunn I'll commit the PR asap 👍

#7 @imath
11 months ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 13592:

Clear the Groups cache incrementor after a group member removal

Do reset the Groups cache incrementor once the 'groups_member_after_remove' action is fired. Although in most configs this extra action is not needed, adding it makes sure the corresponding cached results is cleared when using the Memcached plugin.

Props iandunn

Fixes #9000
Closes https://github.com/buddypress/buddypress/pull/171

#8 @iandunn
11 months ago

Thanks!

Note: See TracTickets for help on using tickets.