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

git-svn-id: https://develop.svn.wordpress.org/trunk@34310 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-09-18 19:27:39 +00:00
parent b0b36bc346
commit 2fd81992bc
4 changed files with 106 additions and 45 deletions

View File

@@ -2376,6 +2376,30 @@ function update_comment_cache( $comments, $update_meta_cache = true ) {
}
}
/**
* Adds any comments from the given IDs to the cache that do not already exist in cache.
*
* @since 4.4.0
* @access private
*
* @see update_comment_cache()
*
* @global wpdb $wpdb
*
* @param array $comment_ids Array of comment IDs.
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
*/
function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
global $wpdb;
$non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
if ( !empty( $non_cached_ids ) ) {
$fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
update_comment_cache( $fresh_comments, $update_meta_cache );
}
}
/**
* Lazy load comment meta when inside of a `WP_Query` loop.
*