Make WordPress Core


Ignore:
Timestamp:
09/18/2015 07:27:39 PM (9 years ago)
Author:
boonebgorges
Message:

Split the comment query.

WP_Comment_Query now fetches comments in two stages: (1) a query to get the
IDs of comments matching the query vars, and (2) a query to populate the
objects corresponding to the matched IDs. The two queries are cached
separately, so that sites with persistent object caches will continue to have
complete cache coverage for normal comment queries.

Splitting the query allows our cache strategy to be more modest and precise, as
full comment data is only stored once per comment. It also makes it possible
to introduce logic for paginated threading, which is necessary to address
certain performance problems.

See #8071.
data is only stored once per comment, instead of along with

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-functions.php

    r34270 r34310  
    23782378
    23792379/**
     2380 * Adds any comments from the given IDs to the cache that do not already exist in cache.
     2381 *
     2382 * @since 4.4.0
     2383 * @access private
     2384 *
     2385 * @see update_comment_cache()
     2386 *
     2387 * @global wpdb $wpdb
     2388 *
     2389 * @param array $comment_ids       Array of comment IDs.
     2390 * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
     2391 */
     2392function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
     2393    global $wpdb;
     2394
     2395    $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
     2396    if ( !empty( $non_cached_ids ) ) {
     2397        $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     2398
     2399        update_comment_cache( $fresh_comments, $update_meta_cache );
     2400    }
     2401}
     2402
     2403/**
    23802404 * Lazy load comment meta when inside of a `WP_Query` loop.
    23812405 *
Note: See TracChangeset for help on using the changeset viewer.