Skip to:
Content

BuddyPress.org

Changeset 13592


Ignore:
Timestamp:
10/11/2023 02:09:00 AM (2 years ago)
Author:
imath
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-cache.php

    r13309 r13592  
    326326    return bp_core_reset_incrementor( 'bp_groups' );
    327327}
    328 add_action( 'groups_group_after_save', 'bp_groups_reset_cache_incrementor' );
    329 add_action( 'bp_groups_delete_group',  'bp_groups_reset_cache_incrementor' );
    330 add_action( 'updated_group_meta',      'bp_groups_reset_cache_incrementor' );
    331 add_action( 'deleted_group_meta',      'bp_groups_reset_cache_incrementor' );
    332 add_action( 'added_group_meta',        'bp_groups_reset_cache_incrementor' );
     328add_action( 'groups_group_after_save',    'bp_groups_reset_cache_incrementor' );
     329add_action( 'bp_groups_delete_group',     'bp_groups_reset_cache_incrementor' );
     330add_action( 'updated_group_meta',         'bp_groups_reset_cache_incrementor' );
     331add_action( 'deleted_group_meta',         'bp_groups_reset_cache_incrementor' );
     332add_action( 'added_group_meta',           'bp_groups_reset_cache_incrementor' );
     333add_action( 'groups_member_after_remove', 'bp_groups_reset_cache_incrementor' );
    333334
    334335/**
  • trunk/tests/phpunit/testcases/groups/cache.php

    r13103 r13592  
    66 */
    77class BP_Tests_Group_Cache extends BP_UnitTestCase {
     8
    89    /**
    910     * @group bp_groups_update_meta_cache
     
    280281        $this->assertEquals( 3, BP_Groups_Group::get_total_group_count() );
    281282    }
     283
     284    /**
     285     * @ticket BP9000
     286     */
     287    public function test_groups_get_groups_for_user_cache_once_left() {
     288        $g = self::factory()->group->create();
     289        $u = self::factory()->user->create();
     290
     291        groups_join_group( $g, $u );
     292        $u_groups = groups_get_groups( array( 'user_id' => $u ) );
     293        $u_group_ids = wp_list_pluck( $u_groups['groups'], 'id' );
     294
     295        $this->assertContains( $g, $u_group_ids );
     296
     297        groups_leave_group( $g, $u );
     298        $u_groups = groups_get_groups( array( 'user_id' => $u ) );
     299        $u_group_ids = wp_list_pluck( $u_groups['groups'], 'id' );
     300
     301        $this->assertNotContains( $g, $u_group_ids );
     302    }
     303
     304    /**
     305     * @ticket BP9000
     306     */
     307    public function test_groups_get_groups_for_user_cache_once_removed() {
     308        $g = self::factory()->group->create();
     309        $u = self::factory()->user->create();
     310
     311        groups_join_group( $g, $u );
     312        $u_groups = groups_get_groups( array( 'user_id' => $u ) );
     313        $u_group_ids = wp_list_pluck( $u_groups['groups'], 'id' );
     314
     315        $this->assertContains( $g, $u_group_ids );
     316
     317        add_filter( 'bp_is_item_admin', '__return_true' );
     318        groups_remove_member( $u, $g );
     319        remove_filter( 'bp_is_item_admin', '__return_true' );
     320
     321        $u_groups = groups_get_groups( array( 'user_id' => $u ) );
     322        $u_group_ids = wp_list_pluck( $u_groups['groups'], 'id' );
     323
     324        $this->assertNotContains( $g, $u_group_ids );
     325    }
    282326}
Note: See TracChangeset for help on using the changeset viewer.