Improvements to group and activity meta performance

Several recent changes in the BuddyPress trunk have added better cache support for group meta (r5460) and activity meta (r5505). In brief, these changesets make it so that every time you call up groups or activity (as in, for example, bp_has_groups() or bp_has_activities()), BuddyPress will automatically fetch all of the metadata for those items and add it to the WordPress object cache. The net effect of these changes is that, inside of the group and activity loops, the performance of groups_get_groupmeta() and bp_activity_get_meta() is radically improved, since individual database queries are no longer required. (This behavior is modeled on how WordPress handles postmeta after a posts query – our new bp_update_meta_cache() is based on WP’s update_meta_cache().)

For the most part, plugin authors do not need to do anything to take advantage of these new features. However, in order to make bp_update_meta_cache() as flexible as possible, the format of the keys used to cache activity meta has changed. It used to be of the form:

'bp_activity_meta_' . $meta_key . '_' . $activity_id

but is now of the form

'bp_activity_meta_' . $activity_id . '_' . $meta_key

to better match other components. As a result, your activity meta cache will be flushed when you upgrade to BP 1.6. And if you made any manual references to the activity meta cache in your own plugin, you’ll need to change those references. (If you used bp_activity_update_meta() and bp_activity_get_meta(), you don’t need to do anything.) This should affect very, very few (if any) BP customizations.