Skip to:
Content

BuddyPress.org

Changeset 7051


Ignore:
Timestamp:
05/09/2013 02:26:50 PM (11 years ago)
Author:
boonebgorges
Message:

When deleting an activity item, clear its metadata cache

Because of the way that the cache groups are structured, there is no simple
way to figure out which cache keys should be dropped upon deletion. Our
solution is to scan through all the keys in the 'bp' group to determine the
relevant ones. It's not particularly elegant, but this kind of cache-busting
will happen rarely (namely, when an activity item is deleted) so the overhead
is negligible.

Fixes #4804

Location:
trunk/bp-activity
Files:
2 edited

Legend:

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

    r6342 r7051  
    3333        'cache_key_prefix' => 'bp_activity_meta'
    3434    );
    35    
     35
    3636    bp_update_meta_cache( $cache_args );
    3737}
     38
     39/**
     40 * Clear the cache for all metadata of a given activity
     41 *
     42 * @param int $activity_id
     43 */
     44function bp_activity_clear_meta_cache_for_activity( $activity_id ) {
     45    global $wp_object_cache;
     46
     47    if ( is_object( $wp_object_cache ) && ! empty( $wp_object_cache->cache['bp'] ) ) {
     48        foreach ( $wp_object_cache->cache['bp'] as $ckey => $cvalue ) {
     49            if ( 0 === strpos( $ckey, 'bp_activity_meta_' . $activity_id ) ) {
     50                wp_cache_delete( $ckey, 'bp' );
     51            }
     52        }
     53    }
     54}
  • trunk/bp-activity/bp-activity-classes.php

    r7048 r7051  
    480480        $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );
    481481
     482        foreach ( (array) $activity_ids as $activity_id ) {
     483            bp_activity_clear_meta_cache_for_activity( $activity_id );
     484        }
     485
    482486        return $wpdb->query( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" );
    483487    }
Note: See TracChangeset for help on using the changeset viewer.