Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/18/2014 12:50:11 PM (8 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-template.php

    r7828 r7918  
    170170     * @param string $page_arg The string used as a query parameter in
    171171     *        pagination links. Default: 'bpage'.
    172      */
    173     function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) {
     172     * @param bool $update_meta_cache Whether to pre-fetch metadata for
     173     *        queried blogs.
     174     */
     175    function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true ) {
    174176
    175177        $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
     
    179181            $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
    180182        else
    181             $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
     183            $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'update_meta_cache' => $update_meta_cache, ) );
    182184
    183185        if ( !$max || $max >= (int) $this->blogs['total'] )
     
    360362
    361363        'user_id'      => $user_id,       // Pass a user_id to limit to only blogs this user has higher than subscriber access to
    362         'search_terms' => $search_terms   // Pass search terms to filter on the blog title or description.
     364        'search_terms' => $search_terms,  // Pass search terms to filter on the blog title or description.
     365        'update_meta_cache' => true,
    363366    );
    364367
     
    379382    }
    380383
    381     $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg );
     384    $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg, $update_meta_cache );
    382385    return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
    383386}
Note: See TracChangeset for help on using the changeset viewer.