Make WordPress Core


Ignore:
Timestamp:
02/14/2012 03:09:35 PM (13 years ago)
Author:
ryan
Message:

Split the main WP_Query posts query into two queries to avoid temp tables. Leverage cache to avoid second query in persistent cache environments. Props scribu, cheald, prettyboymp. see #18536

File:
1 edited

Legend:

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

    r19910 r19918  
    53195319    }
    53205320}
     5321
     5322/**
     5323 * Adds any posts from the given ids to the cache that do not already exist in cache
     5324 *
     5325 * @since 3.4.0
     5326 *
     5327 * @access private
     5328 *
     5329 * @param array $post_ids ID list
     5330 * @param bool $update_term_cache Whether to update the term cache. Default is true.
     5331 * @param bool $update_meta_cache Whether to update the meta cache. Default is true.
     5332 */
     5333function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) {
     5334    global $wpdb;
     5335
     5336    $non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
     5337    if ( !empty( $non_cached_ids ) ) {
     5338        $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );
     5339
     5340        update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
     5341    }
     5342}
     5343
Note: See TracChangeset for help on using the changeset viewer.