Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/03/2014 09:35:48 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce bp_core_user_displaynames(), for quick, bulk displayname lookup

The technique BP uses for determining a user's displayname takes into
consideration whether the xprofile component is active, whether the user has a
WP display_name, and a number of other factors. Because the values are used so
often throughout BP, they are then cached in WP's object cache. However, there
are a number of places throughout BuddyPress where displaynames are fetched
in a way that is inconsistent with the "canonical" workflow (ie, by querying
the xprofile tables correctly). This causes inconsistent results, and also can
result in performance degradation when the persistent cache is skipped.
Moreover, the singular nature of bp_core_get_user_displayname() meant that
doing it the "right" way meant introducing large numbers of queries to a given
page load.

This changeset introduces bp_core_get_user_displaynames(), which contains all
the critical logic of bp_core_get_user_displayname() - including fallbacks for
various setups and support for the object cache - but allows for fetching large
numbers of displaynames without multiple queries. bp_core_get_user_displayname()
is now a wrapper for the more general function.

The function has been swapped in throughout BuddyPress as appropriate.

See #5445

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r8005 r8027  
    545545
    546546            if ( ! empty( $activity_user_ids ) ) {
    547                 $names = BP_XProfile_ProfileData::get_value_byid( 1, $activity_user_ids );
    548                 if ( ! empty( $names ) ) {
    549 
    550                     $tmp_names = array();
    551 
    552                     foreach ( (array) $names as $name ) {
    553                         $tmp_names[ $name->user_id ] = $name->value;
    554                     }
    555 
     547                $fullnames = bp_core_get_user_displaynames( $activity_user_ids );
     548                if ( ! empty( $fullnames ) ) {
    556549                    foreach ( (array) $activities as $i => $activity ) {
    557                         if ( ! empty( $tmp_names[ $activity->user_id ] ) ) {
    558                             $activities[ $i ]->user_fullname = $tmp_names[ $activity->user_id ];
     550                        if ( ! empty( $fullnames[ $activity->user_id ] ) ) {
     551                            $activities[ $i ]->user_fullname = $fullnames[ $activity->user_id ];
    559552                        }
    560553                    }
    561 
    562                     unset( $names );
    563                     unset( $tmp_names );
    564554                }
    565555            }
Note: See TracChangeset for help on using the changeset viewer.