mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Improve user listing performance. Props miqrogroove. see #11914
git-svn-id: https://develop.svn.wordpress.org/trunk@13576 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -139,6 +139,38 @@ function get_userdata( $user_id ) {
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( !function_exists('cache_users') ) :
|
||||
/**
|
||||
* Retrieve info for user lists to prevent multiple queries by get_userdata()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array $users User ID numbers list
|
||||
*/
|
||||
function cache_users( $users ) {
|
||||
global $wpdb;
|
||||
|
||||
$clean = array();
|
||||
foreach($users as $id) {
|
||||
$id = (int) $id;
|
||||
if (wp_cache_get($id, 'users')) {
|
||||
// seems to be cached already
|
||||
} else {
|
||||
$clean[] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 0 == count($clean) )
|
||||
return;
|
||||
|
||||
$list = implode(',', $clean);
|
||||
|
||||
$results = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)");
|
||||
|
||||
_fill_many_users($results);
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( !function_exists('get_user_by') ) :
|
||||
/**
|
||||
* Retrieve user info by a given field
|
||||
|
||||
Reference in New Issue
Block a user