Skip to:

Opened 12 years ago

Closed 12 years ago

#3799 closed enhancement (fixed)

Grab and cache groupmeta when viewinga group page

Reported by: boonebgorges's profile boonebgorges Owned by:
Milestone: 1.6 Priority: normal
Severity: major Version:
Component: Groups Keywords: dev-feedback


Lots of plugins use groupmeta. If you use 5 different pieces of groupmeta in a group, it adds 5 queries to each page load. We should be a bit more generous about this in BP core.

I propose that we do two things:

  • Refactor BP_Groups_Group::populate(). Remove the join against groupmeta in the initial query. Instead, do a single query for all groupmeta associated with that group. Then, we can stash the results in the $bp->groups->current_group object (kinda like WP does with the current_user object), or in the WP cache (like WP does with postmeta), or both.
  • Add a sweep of groupmeta to BP_Groups_Group::get(), so that the groupmeta for all the returned groups is either put into the WP cache or passed back with the resulting object. Because this could potentially be a large amount of data (especially if people are calling up large number of groups in utility functions), we should probably have a way to disable this with an optional parameter.

We can look to WP's nice update_meta_cache() for guidance on how to do this. We can probably do the same thing for both of my suggestions.

I'm happy to whip up a patch, but would be happy to get some feedback first. This is pretty painless, so could pretty easily go into BP 1.6 if I get a patch up in the next week or so. Otherwise it's puntable.

Attachments (1)

3799.01.patch (6.5 KB) - added by boonebgorges 12 years ago.

Download all attachments as: .zip

Change History (5)

#1 @r-a-y
12 years ago

Gigantic +1!

Should probably do this for the activity component as well.

#2 @boonebgorges
12 years ago

This patch is not complete. For educational purposes only! Just to give you an idea.

#3 @boonebgorges
12 years ago

I'm about to commit a working version of this. Going to mark this ticket as resolved and open a separate ticket for the activity stuff. If issues arise with the group version, feel free to reopen this ticket.

#4 @boonebgorges
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5460]) Introduces automatic meta cache features.
Introduces bp_update_meta_cache(), for collecting all metadata associated with an object or with multiple objects in one fell swoop, and adding it to the WP cache for quicker access later
Introduces bp_groups_update_meta_cache(), for collecting groupmeta at the beginning of a group loop
Modifies the BP_Groups_Group object so that groupmeta is fetched in the populate() and get() methods
Fixes #3799

Note: See TracTickets for help on using tickets.