WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/03/2010 07:08:30 PM (12 years ago)
Author:
ryan
Message:

Improve user listing performance. Props miqrogroove. see #11914

File:
1 edited

Legend:

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

    r13560 r13576  
    137137
    138138    return $user;
     139}
     140endif;
     141
     142if ( !function_exists('cache_users') ) :
     143/**
     144 * Retrieve info for user lists to prevent multiple queries by get_userdata()
     145 *
     146 * @since 3.0.0
     147 *
     148 * @param array $users User ID numbers list
     149 */
     150function cache_users( $users ) {
     151    global $wpdb;
     152
     153    $clean = array();
     154    foreach($users as $id) {
     155        $id = (int) $id;
     156        if (wp_cache_get($id, 'users')) {
     157            // seems to be cached already
     158        } else {
     159            $clean[] = $id;
     160        }
     161    }
     162
     163    if ( 0 == count($clean) )
     164        return;
     165
     166    $list = implode(',', $clean);
     167
     168    $results = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)");
     169   
     170    _fill_many_users($results);
    139171}
    140172endif;
Note: See TracChangeset for help on using the changeset viewer.