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.

git-svn-id: https://develop.svn.wordpress.org/trunk@34730 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-10-01 03:57:53 +00:00
parent f14dc03ad6
commit a7dbb948c5
2 changed files with 31 additions and 1 deletions

View File

@@ -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;