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
Built from https://develop.svn.wordpress.org/trunk@34310


git-svn-id: http://core.svn.wordpress.org/trunk@34274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges
2015-09-18 19:28:51 +00:00
parent 04f7a0da2f
commit c6c9f8ad26
3 changed files with 99 additions and 46 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.
*