Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/19/2009 01:35:32 PM (16 years ago)
Author:
apeatling
Message:

Added basic object caching support ready for the first release. This will cut the number of database calls and load by 3x. Add define( 'WP_CACHE', true ); to you wp-config.php and drop object-cache.php into /wp-content/ to enable.

A good file based object cache is available here:
http://neosmart.net/dl.php?id=14

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-templatetags.php

    r1232 r1238  
    232232function bp_fetch_user_fullname( $user_id = false, $echo = true ) {
    233233    global $bp;
    234 
     234   
    235235    if ( !$user_id )
    236236        $user_id = $bp->displayed_user->id;
    237 
    238     if ( function_exists('xprofile_install') ) {
    239         $data = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
    240 
    241         if ( empty($data) ) {
     237   
     238    if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
     239        if ( function_exists('xprofile_install') ) {
     240            $fullname = bp_core_ucfirst( xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id ) );
     241
     242            if ( empty($fullname) ) {
     243                $ud = get_userdata($user_id);
     244                $fullname = bp_core_ucfirst($ud->user_login);
     245
     246                xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $data );
     247            }
     248        } else {
    242249            $ud = get_userdata($user_id);
    243             $data = bp_core_ucfirst($ud->user_login);
    244            
    245             xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $data );
    246         } else {
    247             $data = bp_core_ucfirst($data);
     250            $fullname = $ud->user_login;
    248251        }
    249     } else {
    250         $ud = get_userdata($user_id);
    251         $data = $ud->user_login;
     252
     253        wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
    252254    }
    253255
    254256    if ( $echo )
    255         echo apply_filters( 'bp_fetch_user_fullname', stripslashes( trim( $data ) ) );
     257        echo apply_filters( 'bp_fetch_user_fullname', stripslashes( trim( $fullname ) ) );
    256258    else
    257         return apply_filters( 'bp_fetch_user_fullname', stripslashes ( trim ( $data ) ) );
     259        return apply_filters( 'bp_fetch_user_fullname', stripslashes ( trim ( $fullname ) ) );
    258260}
    259261
Note: See TracChangeset for help on using the changeset viewer.