Skip to:
Content

BuddyPress.org

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#5398 closed enhancement (fixed)

Review metadata caching across components

Reported by: boonebgorges Owned by: boonebgorges
Milestone: 2.0 Priority: normal
Severity: normal Version:
Component: Core Keywords:
Cc:

Description

After the migrations in #4551, caching for component metadata now uses WP's core schema for caching. A review is required to ensure that the rest of our caching infrastructure is in sync with these changes. In particular:

  • ensure that object meta caches are invalidated correctly on object updates
  • ensure that cache priming is in place and working properly for the template loops (bp_update_meta_cache())

This should already be done for groups and activity, but could use a review. I don't think it was ever done for blogs and xprofile, but this would be a good time to port over the relevant code.

Change History (13)

#1 @boonebgorges
6 years ago

  • Owner set to boonebgorges
  • Status changed from new to assigned

#2 @boonebgorges
6 years ago

In 7894:

Add update_meta_cache param for BP_Groups_Group stack

This allows us to avoid unneeded meta cache pre-fetching, following WP_Query.

See #5398

#3 @boonebgorges
6 years ago

In 7895:

Don't update_meta_cache when querying for groups in activity post form box.

See #5398

#4 @boonebgorges
6 years ago

In 7898:

Introduce $args param to BP_Groups_Group constructor and groups_get_group()

This argument array can contain the following toggles:

  • update_meta_cache (pre-fetch all group metadata for the queried group)
  • populate_extras (pre-fetch last activity, admin/mod lists, and current user access/membership status in queried group)

Both items default to false, for backward compatibility

Allowing these pre-fetch toggles to be set to false allows us to avoid large
numbers of unnecessary database queries in certain cases, such as when
secondary avatars are populated on activity directories.

See #5398

#5 @boonebgorges
6 years ago

In 7899:

When fetching the group in bp_get_activity_secondary_avatar(), don't get group extras

We have no need for membership info, etc, so we avoid a number of queries here.

See #5398

#6 @boonebgorges
6 years ago

In 7901:

Don't prime activitymeta cache in BP_Activity_Activity::construct()

bp_activity_get_meta() now uses the core API functions. get_metadata() works by
priming the cache with *all* object metadata when requesting any piece of
metadata for that object. This means that, instead of pre-fetching activitymeta
when instantiating BP_Activity_Activity, we wait until it happens in
get_metadata(). At best, this can help us to avoid pre-fetching a meta cache
that will not be used.

See #5398

#7 @boonebgorges
6 years ago

In 7903:

Don't prime groupmeta cache in BP_Groups_Group::construct()

groups_get_groupmeta() now uses the core API functions. get_metadata() works by
priming the cache with *all* object metadata when requesting any piece of
metadata for that object. This means that, instead of pre-fetching groupmeta
when instantiating BP_Groups_Group, we wait until it happens in get_metadata().
At best, this can help us to avoid pre-fetching a meta cache that will not be
used.

See #5398

#8 @boonebgorges
6 years ago

In 7905:

Introduce 'update_meta_cache' param to bp_has_activities() stack

See #5398

#9 @boonebgorges
6 years ago

In 7914:

Introduce metadata pre-fetching for xprofile objects

XProfile objects (groups, fields, and data) are generally fetched in a nested
way, as within the context of a bp_has_profile() loop. Thus, it makes sense to
pre-fetch xprofile metadata within a bp_has_profile() loop in a nested way as
well. This changeset introduces bp_xprofile_update_meta_cache(), which is able
to fetch all uncached metadata for nested meta types with a single database
query.

This changeset also introduces an 'update_meta_cache' parameter to the
bp_has_profile() stack. This param allows developers to disable the pre-
fetching introduced here. Defaults to true.

See #5398

#10 @boonebgorges
6 years ago

In 7915:

Don't use fetch_default_visibility_levels() method in bp_has_profile() loop

There's no need to do this custom pre-fetching of visibility levels within
the bp_has_profile() loop, because the values are already loaded into the cache
by bp_xprofile_update_meta_cache(). So we use bp_xprofile_get_meta() instead.

See #5398

#11 @boonebgorges
6 years ago

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

In 7918:

Pre-fetch blogmeta when in blog loops

This reduces overhead when querying for blog meta in the context of a
bp_has_blogs() template loop. Mirrors similar functionality in the activity,
groups, and xprofile components.

Also introduces an update_meta_cache parameter to the bp_has_blogs() stack, so
that plugin/theme authors can disable this pre-fetching.

Fixes #5398

#12 @DJPaul
3 years ago

  • Type changed from task to enhancement

#13 @boonebgorges
3 years ago

In 11056:

Activity: Ensure that 'update_meta_cache' param is passed through bp_activity_get().

Missed in [7905].

See #5398.

Note: See TracTickets for help on using tickets.