[buddypress-trac] [BuddyPress Trac] #5815: bp_blogs_total_blogs_for_user() queries database on each page view in multisite

buddypress-trac noreply at wordpress.org
Thu Aug 14 21:12:55 UTC 2014


#5815: bp_blogs_total_blogs_for_user() queries database on each page view in
multisite
--------------------------+------------------------------
 Reporter:  wpdennis      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Blogs         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |
--------------------------+------------------------------

Comment (by wpdennis):

 Something like this seems to work:

 {{{
 function bp_blogs_total_blogs_for_user( $user_id = 0 ) {

         if ( empty( $user_id ) )
                 $user_id = ( bp_displayed_user_id() ) ?
 bp_displayed_user_id() : bp_loggedin_user_id();

         if ( absint($user_id) === 0 )
                 return 0;

         if (false === $count = wp_cache_get( 'bp_total_blogs_for_user_' .
 $user_id, 'bp' ) ) {
                 $count = BP_Blogs_Blog::total_blog_count_for_user(
 $user_id );
                 wp_cache_set( 'bp_total_blogs_for_user_' . $user_id,
 $count, 'bp' );
         }

         return $count;
 }
 }}}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5815#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list