Make WordPress Core


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

Meta data caching improvements. Props mdawaffe. see #15545

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.