Changeset 7956
- Timestamp:
- 02/21/2014 05:51:10 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-cache.php
r7844 r7956 65 65 */ 66 66 function bp_groups_delete_group_cache( $group_id = 0 ) { 67 wp_cache_delete( 'bp_groups_group_' . $group_id . '_load_users', 'bp' ); 68 wp_cache_delete( 'bp_groups_group_' . $group_id . '_noload_users', 'bp' ); 67 wp_cache_delete( $group_id, 'bp_groups' ); 69 68 } 70 69 add_action( 'groups_delete_group', 'bp_groups_delete_group_cache' ); … … 79 78 */ 80 79 function bp_groups_delete_group_cache_on_metadata_change( $meta_id, $group_id ) { 81 wp_cache_delete( 'bp_groups_group_' . $group_id . '_load_users', 'bp' ); 82 wp_cache_delete( 'bp_groups_group_' . $group_id . '_noload_users', 'bp' ); 80 wp_cache_delete( $group_id, 'bp_groups' ); 83 81 } 84 82 add_action( 'updated_group_meta', 'bp_groups_delete_group_cache_on_metadata_change', 10, 2 ); -
trunk/bp-groups/bp-groups-classes.php
r7948 r7956 177 177 global $wpdb, $bp; 178 178 179 if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ) ) { 180 $this->id = $group->id; 181 $this->creator_id = $group->creator_id; 182 $this->name = stripslashes($group->name); 183 $this->slug = $group->slug; 184 $this->description = stripslashes($group->description); 185 $this->status = $group->status; 186 $this->enable_forum = $group->enable_forum; 187 $this->date_created = $group->date_created; 179 $group = wp_cache_get( $this->id, 'bp_groups' ); 180 if ( false === $group ) { 181 $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ); 182 183 if ( empty( $group ) ) { 184 $this->id = 0; 185 return; 186 } 187 188 $this->id = $group->id; 189 $this->creator_id = $group->creator_id; 190 $this->name = stripslashes( $group->name ); 191 $this->slug = $group->slug; 192 $this->description = stripslashes( $group->description ); 193 $this->status = $group->status; 194 $this->enable_forum = $group->enable_forum; 195 $this->date_created = $group->date_created; 188 196 189 197 if ( ! empty( $this->args['populate_extras'] ) ) { 190 198 $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' ); 191 199 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' ); 192 $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id ); 193 $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id ); 194 $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id ); 200 201 // Get group admins and mods 202 $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) ); 203 204 foreach ( (array) $admin_mods as $user ) { 205 if ( (int) $user->is_admin ) { 206 $this->admins[] = $user; 207 } else { 208 $this->mods[] = $user; 209 } 210 } 211 212 // Cache general (non-user-specific) 213 // information about the group 214 wp_cache_set( $this->id, $this, 'bp_groups' ); 215 } 216 217 // Set user-specific data 218 if ( ! empty( $this->args['populate_extras'] ) ) { 219 $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id ); 220 $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id ); 221 $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id ); 195 222 196 223 // If this is a private or hidden group, does the current user have access? … … 203 230 $this->user_has_access = true; 204 231 } 205 206 // Get group admins and mods207 $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );208 foreach( (array) $admin_mods as $user ) {209 if ( (int) $user->is_admin )210 $this->admins[] = $user;211 else212 $this->mods[] = $user;213 }214 232 } 215 } else {216 $this->id = 0;217 233 } 218 234 } … … 289 305 do_action_ref_array( 'groups_group_after_save', array( &$this ) ); 290 306 291 wp_cache_delete( 'bp_groups_group_' . $this->id, 'bp' );307 wp_cache_delete( $this->id, 'bp_groups' ); 292 308 293 309 return true; … … 317 333 do_action_ref_array( 'bp_groups_delete_group', array( &$this, $user_ids ) ); 318 334 319 wp_cache_delete( 'bp_groups_group_' . $this->id, 'bp' );335 wp_cache_delete( $this->id, 'bp_groups' ); 320 336 321 337 // Finally remove the group entry from the DB -
trunk/bp-groups/bp-groups-functions.php
r7948 r7956 41 41 */ 42 42 function groups_get_group( $args = '' ) { 43 $ defaults =array(43 $r = wp_parse_args( $args, array( 44 44 'group_id' => false, 45 45 'load_users' => false, 46 46 'populate_extras' => true, 47 ) ); 48 49 $group_args = array( 50 'populate_extras' => $r['populate_extras'], 47 51 ); 48 52 49 $args = wp_parse_args( $args, $defaults ); 50 extract( $args, EXTR_SKIP ); 51 52 $cache_key = 'bp_groups_group_' . $group_id . ( $load_users ? '_load_users' : '_noload_users' ); 53 54 if ( !$group = wp_cache_get( $cache_key, 'bp' ) ) { 55 $group_args = array( 56 'populate_extras' => $populate_extras, 57 ); 58 59 $group = new BP_Groups_Group( $group_id, $group_args ); 60 wp_cache_set( $cache_key, $group, 'bp' ); 61 } 53 $group = new BP_Groups_Group( $r['group_id'], $group_args ); 62 54 63 55 return apply_filters( 'groups_get_group', $group ); -
trunk/tests/testcases/groups/cache.php
r7843 r7956 74 74 75 75 // Prime cache 76 groups_get_group( array( 'group_id' => $g ) );76 groups_get_group( array( 'group_id' => $g, ) ); 77 77 78 $this->assertNotEmpty( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );78 $this->assertNotEmpty( wp_cache_get( $g, 'bp_groups' ) ); 79 79 80 80 // Trigger flush 81 81 groups_update_groupmeta( $g, 'foo', 'bar' ); 82 82 83 $this->assertFalse( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );83 $this->assertFalse( wp_cache_get( $g, 'bp_groups' ) ); 84 84 } 85 85 … … 95 95 groups_get_group( array( 'group_id' => $g ) ); 96 96 97 $this->assertNotEmpty( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );97 $this->assertNotEmpty( wp_cache_get( $g, 'bp_groups' ) ); 98 98 99 99 // Trigger flush 100 100 groups_update_groupmeta( $g, 'foo', 'baz' ); 101 $this->assertFalse( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );101 $this->assertFalse( wp_cache_get( $g, 'bp_groups' ) ); 102 102 } 103 103 -
trunk/tests/testcases/groups/class-bp-groups-group.php
r7938 r7956 644 644 645 645 /** 646 * @group delete 647 * @group cache 648 */ 649 public function test_delete_clear_cache() { 650 $g = $this->factory->group->create(); 651 652 // Prime cache 653 groups_get_group( array( 'group_id' => $g, ) ); 654 655 $this->assertNotEmpty( wp_cache_get( $g, 'bp_groups' ) ); 656 657 $group = new BP_Groups_Group( $g ); 658 $group->delete(); 659 660 $this->assertFalse( wp_cache_get( $g, 'bp_groups' ) ); 661 } 662 663 /** 664 * @group save 665 * @group cache 666 */ 667 public function test_save_clear_cache() { 668 $g = $this->factory->group->create(); 669 670 // Prime cache 671 groups_get_group( array( 'group_id' => $g, ) ); 672 673 $this->assertNotEmpty( wp_cache_get( $g, 'bp_groups' ) ); 674 675 $group = new BP_Groups_Group( $g ); 676 $group->name = 'Foo'; 677 $group->save(); 678 679 $this->assertFalse( wp_cache_get( $g, 'bp_groups' ) ); 680 } 681 /** 646 682 * @group get_group_extras 647 683 */ -
trunk/tests/testcases/groups/functions.php
r7903 r7956 549 549 $this->assertNotEmpty( groups_add_groupmeta( $g, 'foo', 'baz' ) ); 550 550 } 551 552 /** 553 * @group groups_get_group 554 * @group cache 555 */ 556 public function test_groups_get_group_cache_different_users() { 557 $g = $this->factory->group->create(); 558 $u1 = $this->create_user(); 559 $u2 = $this->create_user(); 560 $this->add_user_to_group( $u1, $g ); 561 562 $old_user = get_current_user_id(); 563 $this->set_current_user( $u1 ); 564 565 $group1 = groups_get_group( array( 'group_id' => $g, ) ); 566 567 $this->set_current_user( $u2 ); 568 569 $group2 = groups_get_group( array( 'group_id' => $g, ) ); 570 571 $this->assertNotEquals( $group1, $group2 ); 572 573 $this->set_current_user( $old_user ); 574 } 551 575 }
Note: See TracChangeset
for help on using the changeset viewer.