Opened 12 years ago
Closed 12 years ago
#4804 closed defect (bug) (fixed)
Activity meta cache not flushed after BP_Activity_Activity::delete_activity_meta_entries()
Reported by: | boonebgorges | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 1.8 | Priority: | low |
Severity: | minor | Version: | |
Component: | Activity | Keywords: | has-patch 2nd-opinion commit |
Cc: |
Description
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.
#4765 was marked as a duplicate.