Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/14/2012 08:12:59 PM (13 years ago)
Author:
djpaul
Message:

When a group is created or deleted, clear each group member's "total groups count" cache.
Addresses a bug where the counts never changed in an environment with a persistent object cache.

  • See #4226
  • Specify cache group for to wp_cache_delete() in groups_clear_group_user_object_cache().
  • Add $user_ids parameter to the 'bp_groups_delete_group' action to save a repeat DB query later.
  • Add $group object parameter to the 'groups_created_group' action.
File:
1 edited

Legend:

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

    r6093 r6100  
    5050add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' );
    5151
     52/**
     53 * Clears caches for the group creator when a group is created
     54 *
     55 * @param int $group_id
     56 * @param BP_Groups_Group $group_obj
     57 * @since BuddyPress (1.6)
     58 */
     59function bp_groups_clear_group_creator_cache( $group_id, $group_obj ) {
     60    // Clears the 'total groups' for this user
     61    groups_clear_group_user_object_cache( $group_obj->id, $group_obj->creator_id );
     62}
     63add_action( 'groups_created_group', 'bp_groups_clear_group_creator_cache', 10, 2 );
     64
     65/**
     66 * Clears caches for all members in a group when a group is deleted
     67 *
     68 * @param BP_Groups_Group $group_obj
     69 * @param array User IDs who were in this group
     70 * @since BuddyPress (1.6)
     71 */
     72function bp_groups_clear_group_members_caches( $group_obj, $user_ids ) {
     73    // Clears the 'total groups' cache for each member in a group
     74    foreach ( (array) $user_ids as $user_id )
     75        groups_clear_group_user_object_cache( $group_obj->id, $user_id );
     76}
     77add_action( 'bp_groups_delete_group', 'bp_groups_clear_group_members_caches', 10, 2 );
     78
    5279function groups_clear_group_user_object_cache( $group_id, $user_id ) {
    53     wp_cache_delete( 'bp_total_groups_for_user_' . $user_id );
     80    wp_cache_delete( 'bp_total_groups_for_user_' . $user_id, 'bp' );
    5481}
    5582add_action( 'groups_join_group',   'groups_clear_group_user_object_cache', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.