Make WordPress Core

Changeset 16596


Ignore:
Timestamp:
11/26/2010 09:35:26 PM (13 years ago)
Author:
ryan
Message:

Meta data caching improvements. Props mdawaffe. see #15545

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r16437 r16596  
    260260
    261261    if ( !$meta_cache ) {
    262         update_meta_cache($meta_type, $object_id);
    263         $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
     262        $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
     263        $meta_cache = $meta_cache[$object_id];
    264264    }
    265265
     
    310310    $cache_key = $meta_type . '_meta';
    311311    $ids = array();
     312    $cache = array();
    312313    foreach ( $object_ids as $id ) {
    313         if ( false === wp_cache_get($id, $cache_key) )
     314        $cached_object = wp_cache_get( $id, $cache_key );
     315        if ( false === $cached_object )
    314316            $ids[] = $id;
     317        else
     318            $cache[$id] = $cached_object;
    315319    }
    316320
    317321    if ( empty( $ids ) )
    318         return false;
     322        return $cache;
    319323
    320324    // Get meta info
    321325    $id_list = join(',', $ids);
    322     $cache = array();
    323326    $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
    324327        $meta_type), ARRAY_A );
     
    344347        if ( ! isset($cache[$id]) )
    345348            $cache[$id] = array();
    346     }
    347 
    348     foreach ( array_keys($cache) as $object)
    349         wp_cache_add($object, $cache[$object], $cache_key);
     349        wp_cache_add( $id, $cache[$id], $cache_key );
     350    }
    350351
    351352    return $cache;
  • trunk/wp-includes/user.php

    r16497 r16596  
    10381038        $objects[$id] = array();
    10391039
    1040     update_meta_cache('user', $ids);
    1041 
    1042     foreach ( $ids as $id ) {
    1043         $meta = get_metadata('user', $id);
     1040    $metas = update_meta_cache('user', $ids);
     1041
     1042    foreach ( $metas as $id => $meta ) {
    10441043        foreach ( $meta as $key => $metavalues ) {
    10451044            foreach ( $metavalues as $value ) {
Note: See TracChangeset for help on using the changeset viewer.