Make WordPress Core


Ignore:
Timestamp:
09/30/2015 01:34:54 AM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

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

    r34661 r34711  
    24532453}
    24542454
    2455 /**
    2456  * Lazy load comment meta when inside of a `WP_Query` loop.
    2457  *
    2458  * @since 4.4.0
    2459  *
    2460  * @param null $check      The `$check` param passed from the 'pre_comment_metadata' hook.
    2461  * @param int  $comment_id ID of the comment whose metadata is being cached.
    2462  * @return null In order not to short-circuit `get_metadata()`.
    2463  */
    2464 function wp_lazyload_comment_meta( $check, $comment_id ) {
    2465     global $wp_query;
    2466 
    2467     if ( ! empty( $wp_query->comments ) ) {
    2468         // Don't use `wp_list_pluck()` to avoid by-reference manipulation.
    2469         $comment_ids = array();
    2470         foreach ( $wp_query->comments as $comment ) {
    2471             $comment_ids[] = $comment->comment_ID;
    2472         }
    2473         update_meta_cache( 'comment', $comment_ids );
    2474     }
    2475 
    2476     return $check;
    2477 }
    2478 
    24792455//
    24802456// Internal
Note: See TracChangeset for help on using the changeset viewer.