mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@34599 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -138,7 +138,7 @@ class WP_Comment_Query {
|
||||
* @since 4.2.0
|
||||
* @since 4.4.0 `$parent__in` and `$parent__not_in` were added.
|
||||
* @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`,
|
||||
* and `$hierarchical` were added.
|
||||
* `$hierarchical`, and `$update_comment_post_cache` were added.
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query {
|
||||
@@ -238,6 +238,8 @@ class WP_Comment_Query {
|
||||
* 'flat', or false. Default: false.
|
||||
* @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments.
|
||||
* Default true.
|
||||
* @type bool $update_comment_post_cache Whether to prime the cache for comment posts.
|
||||
* Default false.
|
||||
* }
|
||||
*/
|
||||
public function __construct( $query = '' ) {
|
||||
@@ -281,6 +283,7 @@ class WP_Comment_Query {
|
||||
'date_query' => null, // See WP_Date_Query
|
||||
'hierarchical' => false,
|
||||
'update_comment_meta_cache' => true,
|
||||
'update_comment_post_cache' => false,
|
||||
);
|
||||
|
||||
if ( ! empty( $query ) ) {
|
||||
@@ -414,6 +417,16 @@ class WP_Comment_Query {
|
||||
}
|
||||
}
|
||||
|
||||
// Prime comment post caches.
|
||||
if ( $this->query_vars['update_comment_post_cache'] ) {
|
||||
$comment_post_ids = array();
|
||||
foreach ( $_comments as $_comment ) {
|
||||
$comment_post_ids[] = $_comment->comment_post_ID;
|
||||
}
|
||||
|
||||
_prime_post_caches( $comment_post_ids, false, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the comment query results.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user