[buddypress-trac] [BuddyPress] #4804: Activity meta cache not flushed after BP_Activity_Activity::delete_activity_meta_entries()

buddypress-trac noreply at wordpress.org
Tue Feb 5 03:35:24 UTC 2013


#4804: Activity meta cache not flushed after
BP_Activity_Activity::delete_activity_meta_entries()
--------------------------+-----------------------------------
 Reporter:  boonebgorges  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  low           |  Milestone:  Awaiting Review
Component:  Activity      |    Version:
 Severity:  minor         |   Keywords:  has-patch 2nd-opinion
--------------------------+-----------------------------------
 When deleting all of an activity's meta values with
 `BP_Activity_Activity::delete_activity_meta_entries()`, the corresponding
 cache keys are not cleared.

 I've attached a suggested strategy for fixing it. It's pretty ugly:
 because WP's cache API only allows for one level of grouping (which we use
 for `'bp'`), the activity id is stored in the cache key, eg
 'bp_activity_meta_24_foo'. That means that, in order to find all of the
 cached values, we have to examine each cache key. Moreover, the WP Cache
 API doesn't have a method for getting all cache keys registered to a
 group, so the only way to get the keys is to examine the global object
 directly.

 FWIW, the same issue is going to arise with other database methods that
 clear lots of metadata in one query.

 If we don't like the strategy in the attached patch, another option is to
 refactor methods like `delete_activity_meta_entries()` so that they work
 like this:

 {{{
 $meta_keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM
 {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id )
 );
 foreach ( $meta_keys as $meta_key ) {
     bp_activity_delete_meta( $activity_id, $meta_key );
 }
 }}}

 In other words, go through and delete each item one-by-one. That way, the
 cache will be deleted properly each time (easy to do when we have the meta
 key). The disadvantage is that this requires more queries, but from a
 practical point of view, does this matter? The method is only called in BP
 when activity items are deleted, and the UI only allows for up to 20 items
 to be deleted at once. So we might be looking at a couple dozen queries,
 but only in the admin, and only occasionally.

 It's probably not urgent to fix this, because there's not much harm in the
 data hanging around in the cache after the activity item has been deleted
 - what would you do with metadata for a deleted item, after all? But if
 people start using this method to do other kinds of funny business, the
 bug will become more problematic.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4804>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list