Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/18/2014 12:50:11 PM (11 years ago)
Author:
boonebgorges
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-cache.php

    r7555 r7918  
    1414if ( !defined( 'ABSPATH' ) ) exit;
    1515
     16/**
     17 * Slurp up blogmeta for a specified set of blogs.
     18 *
     19 * It grabs all blogmeta associated with all of the blogs passed
     20 * in $blog_ids and adds it to the WP cache. This improves efficiency when
     21 * using querying blogmeta inline.
     22 *
     23 * @param int|str|array $blog_ids Accepts a single blog ID, or a comma-
     24 *        separated list or array of blog IDs.
     25 */
     26function bp_blogs_update_meta_cache( $blog_ids = false ) {
     27    $cache_args = array(
     28        'object_ids'       => $blog_ids,
     29        'object_type'      => buddypress()->blogs->id,
     30        'object_column'    => 'blog_id',
     31        'cache_group'      => 'blog_meta',
     32        'meta_table'       => buddypress()->blogs->table_name_blogmeta,
     33    );
     34
     35    bp_update_meta_cache( $cache_args );
     36}
    1637/**
    1738 * Clear the blog object cache.
Note: See TracChangeset for help on using the changeset viewer.