Make WordPress Core


Ignore:
Timestamp:
09/17/2015 08:00:31 PM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

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

    r34268 r34270  
    23772377}
    23782378
     2379/**
     2380 * Lazy load comment meta when inside of a `WP_Query` loop.
     2381 *
     2382 * @since 4.4.0
     2383 *
     2384 * @param null $check      The `$check` param passed from the 'pre_comment_metadata' hook.
     2385 * @param int  $comment_id ID of the comment whose metadata is being cached.
     2386 * @return null In order not to short-circuit `get_metadata()`.
     2387 */
     2388function wp_lazyload_comment_meta( $check, $comment_id ) {
     2389    global $wp_query;
     2390
     2391    if ( ! empty( $wp_query->comments ) ) {
     2392        // Don't use `wp_list_pluck()` to avoid by-reference manipulation.
     2393        $comment_ids = array();
     2394        foreach ( $wp_query->comments as $comment ) {
     2395            $comment_ids[] = $comment->comment_ID;
     2396        }
     2397        update_meta_cache( 'comment', $comment_ids );
     2398    }
     2399
     2400    return $check;
     2401}
     2402
    23792403//
    23802404// Internal
Note: See TracChangeset for help on using the changeset viewer.