Ticket #5711: 5711.01.patch
File 5711.01.patch, 2.9 KB (added by , 11 years ago) |
---|
-
src/bp-groups/bp-groups-cache.php
173 173 add_action( 'groups_uninvite_user', 'groups_clear_group_user_object_cache', 10, 2 ); 174 174 add_action( 'groups_remove_member', 'groups_clear_group_user_object_cache', 10, 2 ); 175 175 176 /** 177 * Clear group administrator cache. 178 * 179 * @since BuddyPress (2.1.0) 180 * 181 * @param int $group_id The group ID. 182 */ 183 function groups_clear_group_administrator_cache( $group_id ) { 184 wp_cache_delete( $group_id, 'bp_group_admins' ); 185 } 186 add_action( 'groups_promote_member', 'groups_clear_group_administrator_cache' ); 187 add_action( 'groups_demote_member', 'groups_clear_group_administrator_cache' ); 188 add_action( 'groups_delete_group', 'groups_clear_group_administrator_cache' ); 189 176 190 /* List actions to clear super cached pages on, if super cache is installed */ 177 191 add_action( 'groups_join_group', 'bp_core_clear_cache' ); 178 192 add_action( 'groups_leave_group', 'bp_core_clear_cache' ); -
src/bp-groups/bp-groups-classes.php
2626 2626 public static function get_group_administrator_ids( $group_id ) { 2627 2627 global $bp, $wpdb; 2628 2628 2629 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) ); 2629 $group_admins = wp_cache_get( $group_id, 'bp_group_admins' ); 2630 2631 if ( false === $group_admins ) { 2632 $group_admins = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) ); 2633 2634 wp_cache_set( $group_id, $group_admins, 'bp_group_admins' ); 2635 } 2636 2637 return $group_admins; 2630 2638 } 2631 2639 2632 2640 /** -
tests/phpunit/testcases/groups/cache.php
154 154 $this->assertNotEmpty( wp_cache_get( $g1, 'bp_groups' ) ); 155 155 $this->assertNotEmpty( wp_cache_get( $g2, 'bp_groups' ) ); 156 156 } 157 158 /** 159 * @group groups_get_group_admins 160 */ 161 public function test_groups_get_group_admins_cache() { 162 $u1 = $this->create_user(); 163 $u2 = $this->create_user(); 164 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 165 166 // prime cache 167 groups_get_group_admins( $g ); 168 169 // promote user 2 to an admin 170 bp_update_is_item_admin( true ); 171 groups_promote_member( $u2, $g, 'admin' ); 172 173 // assert that cache is invalidated 174 $this->assertEmpty( wp_cache_get( $g, 'bp_group_admins' ) ); 175 176 // assert new cached value 177 $this->assertEquals( 2, count( groups_get_group_admins( $g ) ) ); 178 } 157 179 }