Improve lazyloading of comment meta in WP_Query loops.
Lazy-loading logic is moved to a method on `WP_Query`. This makes it possible for comment feeds to take advantage of metadata lazyloading, in addition to comments loaded via `comments_template()`. This new technique parallels the termmeta lazyloading technique introduced in [34704]. Fixes #34047. Built from https://develop.svn.wordpress.org/trunk@34711 git-svn-id: http://core.svn.wordpress.org/trunk@34675 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -2452,30 +2452,6 @@ function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy load comment meta when inside of a `WP_Query` loop.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param null $check The `$check` param passed from the 'pre_comment_metadata' hook.
|
||||
* @param int $comment_id ID of the comment whose metadata is being cached.
|
||||
* @return null In order not to short-circuit `get_metadata()`.
|
||||
*/
|
||||
function wp_lazyload_comment_meta( $check, $comment_id ) {
|
||||
global $wp_query;
|
||||
|
||||
if ( ! empty( $wp_query->comments ) ) {
|
||||
// Don't use `wp_list_pluck()` to avoid by-reference manipulation.
|
||||
$comment_ids = array();
|
||||
foreach ( $wp_query->comments as $comment ) {
|
||||
$comment_ids[] = $comment->comment_ID;
|
||||
}
|
||||
update_meta_cache( 'comment', $comment_ids );
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
//
|
||||
// Internal
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user