Make WordPress Core


Ignore:
Timestamp:
09/17/2015 07:29:46 PM (9 years ago)
Author:
boonebgorges
Message:

Prime comment meta caches in WP_Comment_Query.

The new 'update_comment_meta_cache' parameter, which defaults to true, can
be used to disable this behavior.

update_comment_cache() has been updated to support an $update_meta_cache
parameter, which also updates to true; this matches the pattern we use for
priming post caches.

See #16894.

File:
1 edited

Legend:

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

    r34253 r34268  
    23582358 *
    23592359 * @since 2.3.0
    2360  *
    2361  * @param array $comments Array of comment row objects
    2362  */
    2363 function update_comment_cache($comments) {
     2360 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
     2361 *
     2362 * @param array $comments          Array of comment row objects
     2363 * @param bool  $update_meta_cache Whether to update commentmeta cache. Default true.
     2364 */
     2365function update_comment_cache( $comments, $update_meta_cache = true ) {
    23642366    foreach ( (array) $comments as $comment )
    23652367        wp_cache_add($comment->comment_ID, $comment, 'comment');
     2368
     2369    if ( $update_meta_cache ) {
     2370        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
     2371        $comment_ids = array();
     2372        foreach ( $comments as $comment ) {
     2373            $comment_ids[] = $comment->comment_ID;
     2374        }
     2375        update_meta_cache( 'comment', $comment_ids );
     2376    }
    23662377}
    23672378
Note: See TracChangeset for help on using the changeset viewer.