Meta data caching improvements. Props mdawaffe. see #15545
git-svn-id: https://develop.svn.wordpress.org/trunk@16596 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
672c3a90f9
commit
8bf835d944
@ -259,8 +259,8 @@ function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
|
|||||||
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
|
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
|
||||||
|
|
||||||
if ( !$meta_cache ) {
|
if ( !$meta_cache ) {
|
||||||
update_meta_cache($meta_type, $object_id);
|
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
|
||||||
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
|
$meta_cache = $meta_cache[$object_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$meta_key )
|
if ( !$meta_key )
|
||||||
@ -309,17 +309,20 @@ function update_meta_cache($meta_type, $object_ids) {
|
|||||||
|
|
||||||
$cache_key = $meta_type . '_meta';
|
$cache_key = $meta_type . '_meta';
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
$cache = array();
|
||||||
foreach ( $object_ids as $id ) {
|
foreach ( $object_ids as $id ) {
|
||||||
if ( false === wp_cache_get($id, $cache_key) )
|
$cached_object = wp_cache_get( $id, $cache_key );
|
||||||
|
if ( false === $cached_object )
|
||||||
$ids[] = $id;
|
$ids[] = $id;
|
||||||
|
else
|
||||||
|
$cache[$id] = $cached_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $ids ) )
|
if ( empty( $ids ) )
|
||||||
return false;
|
return $cache;
|
||||||
|
|
||||||
// Get meta info
|
// Get meta info
|
||||||
$id_list = join(',', $ids);
|
$id_list = join(',', $ids);
|
||||||
$cache = array();
|
|
||||||
$meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
|
$meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
|
||||||
$meta_type), ARRAY_A );
|
$meta_type), ARRAY_A );
|
||||||
|
|
||||||
@ -343,11 +346,9 @@ function update_meta_cache($meta_type, $object_ids) {
|
|||||||
foreach ( $ids as $id ) {
|
foreach ( $ids as $id ) {
|
||||||
if ( ! isset($cache[$id]) )
|
if ( ! isset($cache[$id]) )
|
||||||
$cache[$id] = array();
|
$cache[$id] = array();
|
||||||
|
wp_cache_add( $id, $cache[$id], $cache_key );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( array_keys($cache) as $object)
|
|
||||||
wp_cache_add($object, $cache[$object], $cache_key);
|
|
||||||
|
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1037,10 +1037,9 @@ function get_user_metavalues($ids) {
|
|||||||
foreach ( $ids as $id )
|
foreach ( $ids as $id )
|
||||||
$objects[$id] = array();
|
$objects[$id] = array();
|
||||||
|
|
||||||
update_meta_cache('user', $ids);
|
$metas = update_meta_cache('user', $ids);
|
||||||
|
|
||||||
foreach ( $ids as $id ) {
|
foreach ( $metas as $id => $meta ) {
|
||||||
$meta = get_metadata('user', $id);
|
|
||||||
foreach ( $meta as $key => $metavalues ) {
|
foreach ( $meta as $key => $metavalues ) {
|
||||||
foreach ( $metavalues as $value ) {
|
foreach ( $metavalues as $value ) {
|
||||||
$objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
|
$objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
|
||||||
|
Loading…
Reference in New Issue
Block a user