Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/17/2014 06:11:43 PM (10 years ago)
Author:
boonebgorges
Message:

Improvements to bp_blogs_total_blogs_for_user()

  • Don't bother to check the cache or perform DB queries for users who are not logged in
  • Do a strict type check when checking the cache, to ensure that a cached value of 0 does not result in an unnecessary database hit

Fixes #5815

Props wpdennis, r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r8929 r8935  
    11371137 * Get the total number of blogs being tracked by BP for a specific user.
    11381138 *
     1139 * @since BuddyPress (1.2.0)
     1140 *
    11391141 * @param int $user_id ID of the user being queried. Default: on a user page,
    11401142 *        the displayed user. Otherwise, the logged-in user.
     
    11421144 */
    11431145function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
    1144 
    1145     if ( empty( $user_id ) )
     1146    if ( empty( $user_id ) ) {
    11461147        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    1147 
    1148     if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
     1148    }
     1149
     1150    // no user ID? do not attempt to look at cache
     1151    if ( empty( $user_id ) ) {
     1152        return 0;
     1153    }
     1154
     1155    $count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
     1156    if ( false === $count ) {
    11491157        $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
    11501158        wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
Note: See TracChangeset for help on using the changeset viewer.