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
git-svn-id: http://svn.automattic.com/wordpress/trunk@15698 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fa45b04e6e
commit
da4b33fc83
|
@ -651,7 +651,7 @@ function get_ordered_blogs_of_user( $user_id, $visibility = true ) {
|
|||
|
||||
// Index the blogs by userblog_id and set the visibility flag
|
||||
// Visibility is on by default, unless a linked site then off
|
||||
foreach ( $blogs AS $blog ) {
|
||||
foreach ( $blogs as $blog ) {
|
||||
$blog->visible = true;
|
||||
|
||||
if ( isset( $visible[$blog->userblog_id] ) )
|
||||
|
@ -661,7 +661,7 @@ function get_ordered_blogs_of_user( $user_id, $visibility = true ) {
|
|||
}
|
||||
|
||||
// Add the blogs to our list by order
|
||||
foreach ( (array)$order AS $id ) {
|
||||
foreach ( (array)$order as $id ) {
|
||||
// A previous change was saving the entire blog details into ordered, not just the blog ID - this detects it
|
||||
if ( is_object( $id ) && isset( $id->userblog_id ) )
|
||||
$id = $id->userblog_id;
|
||||
|
@ -673,13 +673,13 @@ function get_ordered_blogs_of_user( $user_id, $visibility = true ) {
|
|||
}
|
||||
|
||||
// Add any blog not yet ordered to the end
|
||||
foreach ( $newblogs AS $blog ) {
|
||||
foreach ( $newblogs as $blog ) {
|
||||
$ordered[$blog->userblog_id] = $blog;
|
||||
}
|
||||
|
||||
// If we're only interested in visible blogs then remove the rest
|
||||
if ( $visibility ) {
|
||||
foreach ( (array)$ordered AS $pos => $blog ) {
|
||||
foreach ( (array)$ordered as $pos => $blog ) {
|
||||
if ( $blog->visible == false )
|
||||
unset( $ordered[$pos] );
|
||||
}
|
||||
|
@ -1053,23 +1053,33 @@ function _fill_user( &$user ) {
|
|||
function get_user_metavalues($ids) {
|
||||
global $wpdb;
|
||||
|
||||
$clean = array_map('intval', $ids);
|
||||
if ( 0 == count($clean) )
|
||||
return $objects;
|
||||
$objects = array();
|
||||
|
||||
$list = implode(',', $clean);
|
||||
$ids = array_map('intval', $ids);
|
||||
foreach ( $ids as $id )
|
||||
$objects[$id] = array();
|
||||
|
||||
if ( 0 == count($ids) ) {
|
||||
return $objects;
|
||||
} elseif ( 1 == count($ids) ) {
|
||||
// Take advantage of the single-user cache
|
||||
$id = $ids[0];
|
||||
$meta = get_metadata('user', $id);
|
||||
foreach ( $meta as $key => $metavalues )
|
||||
foreach ( $metavalues as $value )
|
||||
$objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
$list = implode(',', $ids);
|
||||
|
||||
$show = $wpdb->hide_errors();
|
||||
$metavalues = $wpdb->get_results("SELECT user_id, meta_key, meta_value FROM $wpdb->usermeta WHERE user_id IN ($list)");
|
||||
$wpdb->show_errors($show);
|
||||
|
||||
$objects = array();
|
||||
foreach($clean as $id) {
|
||||
$objects[$id] = array();
|
||||
}
|
||||
foreach($metavalues as $meta_object) {
|
||||
foreach ( $metavalues as $meta_object )
|
||||
$objects[$meta_object->user_id][] = $meta_object;
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue