Prevent extra db queries in `WP_Comment::get_children()`.
`WP_Comment_Query::fill_descendants()` queries for a comment tree in a way that minimizes database overhead, and places the located descendants with their proper parents. However, it doesn't touch leaf nodes - comments with no children - so future calls to `get_children()` on those comment objects result in unnecessary database queries. To prevent this, `fill_descendants()` now sets a `populated_children` flag on all located `WP_Comment` objects. See #8071. Built from https://develop.svn.wordpress.org/trunk@34730 git-svn-id: http://core.svn.wordpress.org/trunk@34694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dd9709d179
commit
b2f253fc8e
|
@ -922,6 +922,11 @@ class WP_Comment_Query {
|
|||
}
|
||||
}
|
||||
|
||||
// Set the 'populated_children' flag, to ensure additional database queries aren't run.
|
||||
foreach ( $ref as $_ref ) {
|
||||
$_ref->populated_children( true );
|
||||
}
|
||||
|
||||
$comments = $threaded_comments;
|
||||
} else {
|
||||
$comments = $all_comments;
|
||||
|
|
|
@ -158,6 +158,15 @@ final class WP_Comment {
|
|||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* Whether children have been populated for this comment object.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected $populated_children = false;
|
||||
|
||||
/**
|
||||
* Post fields.
|
||||
*
|
||||
|
@ -279,8 +288,12 @@ final class WP_Comment {
|
|||
$_args['parent'] = $this->comment_ID;
|
||||
|
||||
if ( is_null( $this->children ) ) {
|
||||
if ( $this->populated_children ) {
|
||||
$this->children = array();
|
||||
} else {
|
||||
$this->children = get_comments( $_args );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'flat' === $_args['format'] ) {
|
||||
$children = array();
|
||||
|
@ -330,6 +343,18 @@ final class WP_Comment {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'populated_children' flag.
|
||||
*
|
||||
* This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
|
||||
* unneeded database queries.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function populated_children( $set ) {
|
||||
$this->populated_children = (bool) $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a non-public property is set.
|
||||
*
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34729';
|
||||
$wp_version = '4.4-alpha-34730';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue