Make WordPress Core


Ignore:
Timestamp:
09/26/2015 04:01:05 PM (9 years ago)
Author:
boonebgorges
Message:

Improve post field lazyloading for comments.

[34583] modified comment queries so that all post fields are no longer loaded
by default. Instead, they are loaded only when requested on individual comment
objects. This changeset improves that flow:

  • WP_Comment magic methods __isset() and __get() should only load the post when a post field is being requested.
  • The new update_comment_post_cache argument for WP_Comment_Query allows developers to specify that, when comments are queried, all of the posts matching those comments should be loaded into cache with a single DB hit. This parameter defaults to false, since typical comment queries are linked to a single post.

Fixes #27571.

File:
1 edited

Legend:

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

    r34561 r34599  
    139139     * @since 4.4.0 `$parent__in` and `$parent__not_in` were added.
    140140     * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`,
    141      *              and `$hierarchical` were added.
     141     *              `$hierarchical`, and `$update_comment_post_cache` were added.
    142142     * @access public
    143143     *
     
    239239     *     @type bool         $update_comment_meta_cache Whether to prime the metadata cache for found comments.
    240240     *                                                   Default true.
     241     *     @type bool         $update_comment_post_cache Whether to prime the cache for comment posts.
     242     *                                                   Default false.
    241243     * }
    242244     */
     
    282284            'hierarchical' => false,
    283285            'update_comment_meta_cache' => true,
     286            'update_comment_post_cache' => false,
    284287        );
    285288
     
    413416                $_comments[] = $_comment;
    414417            }
     418        }
     419
     420        // Prime comment post caches.
     421        if ( $this->query_vars['update_comment_post_cache'] ) {
     422            $comment_post_ids = array();
     423            foreach ( $_comments as $_comment ) {
     424                $comment_post_ids[] = $_comment->comment_post_ID;
     425            }
     426
     427            _prime_post_caches( $comment_post_ids, false, false );
    415428        }
    416429
Note: See TracChangeset for help on using the changeset viewer.