Make WordPress Core

Changeset 15698


Ignore:
Timestamp:
10/04/2010 07:38:32 AM (13 years ago)
Author:
dd32
Message:

get_user_metavalues(): Use cached user objects when querying for a single user, Prevents duplicate usermeta queries from Adminbar. Whitespace & s/AS/as/. See #14772

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r15671 r15698  
    652652    // Index the blogs by userblog_id and set the visibility flag
    653653    // Visibility is on by default, unless a linked site then off
    654     foreach ( $blogs AS $blog ) {
     654    foreach ( $blogs as $blog ) {
    655655        $blog->visible = true;
    656656
     
    662662
    663663    // Add the blogs to our list by order
    664     foreach ( (array)$order AS $id ) {
     664    foreach ( (array)$order as $id ) {
    665665        // A previous change was saving the entire blog details into ordered, not just the blog ID - this detects it
    666666        if ( is_object( $id ) && isset( $id->userblog_id ) )
     
    674674
    675675    // Add any blog not yet ordered to the end
    676     foreach ( $newblogs AS $blog ) {
     676    foreach ( $newblogs as $blog ) {
    677677        $ordered[$blog->userblog_id] = $blog;
    678678    }
     
    680680    // If we're only interested in visible blogs then remove the rest
    681681    if ( $visibility ) {
    682         foreach ( (array)$ordered AS $pos => $blog ) {
     682        foreach ( (array)$ordered as $pos => $blog ) {
    683683            if ( $blog->visible == false )
    684684                unset( $ordered[$pos] );
     
    10541054    global $wpdb;
    10551055
    1056     $clean = array_map('intval', $ids);
    1057     if ( 0 == count($clean) )
     1056    $objects = array();
     1057
     1058    $ids = array_map('intval', $ids);
     1059    foreach ( $ids as $id )
     1060        $objects[$id] = array();
     1061
     1062    if ( 0 == count($ids) ) {
    10581063        return $objects;
    1059 
    1060     $list = implode(',', $clean);
     1064    } elseif ( 1 == count($ids) ) {
     1065        // Take advantage of the single-user cache
     1066        $id = $ids[0];
     1067        $meta = get_metadata('user', $id);
     1068        foreach ( $meta as $key => $metavalues )
     1069            foreach ( $metavalues as $value )
     1070                $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
     1071
     1072        return $objects;
     1073    }
     1074
     1075    $list = implode(',', $ids);
    10611076
    10621077    $show = $wpdb->hide_errors();
     
    10641079    $wpdb->show_errors($show);
    10651080
    1066     $objects = array();
    1067     foreach($clean as $id) {
    1068         $objects[$id] = array();
    1069     }
    1070     foreach($metavalues as $meta_object) {
     1081    foreach ( $metavalues as $meta_object )
    10711082        $objects[$meta_object->user_id][] = $meta_object;
    1072     }
    10731083
    10741084    return $objects;
     
    11151125function _fill_many_users( &$users ) {
    11161126    $ids = array();
    1117     foreach($users as $user_object) {
     1127    foreach( $users as $user_object ) {
    11181128        $ids[] = $user_object->ID;
    11191129    }
     
    11211131    $metas = get_user_metavalues($ids);
    11221132
    1123     foreach($users as $user_object) {
    1124         if (isset($metas[$user_object->ID])) {
     1133    foreach ( $users as $user_object ) {
     1134        if ( isset($metas[$user_object->ID]) ) {
    11251135            _fill_single_user($user_object, $metas[$user_object->ID]);
    11261136        }
Note: See TracChangeset for help on using the changeset viewer.