mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Lazy-load comment meta on single post pages.
[34268] introduced cache priming for commentmeta, enabled by default. To ensure performance on single post pages - where commentmeta is most likely to cause performance issues - we disable up-front cache-priming. Instead, we prime commentmeta caches for all comments in the loop the first time `get_comment_meta()` is called on the page. Props bradt, dd32, wonderboymusic, boonebgorges. Fixes #16894. Built from https://develop.svn.wordpress.org/trunk@34270 git-svn-id: http://core.svn.wordpress.org/trunk@34234 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
93bcd86b2a
commit
32887d3dfb
@ -2376,6 +2376,30 @@ function update_comment_cache( $comments, $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
|
||||
//
|
||||
|
@ -1211,6 +1211,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
|
||||
'orderby' => 'comment_date_gmt',
|
||||
'status' => 'approve',
|
||||
'post_id' => $post->ID,
|
||||
'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
|
||||
);
|
||||
|
||||
if ( $user_ID ) {
|
||||
|
@ -200,6 +200,7 @@ add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' );
|
||||
add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' );
|
||||
add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' );
|
||||
add_filter( 'title_save_pre', 'trim' );
|
||||
add_filter( 'get_comment_metadata', 'wp_lazyload_comment_meta', 10, 2 );
|
||||
|
||||
add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34269';
|
||||
$wp_version = '4.4-alpha-34270';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user