Make WordPress Core


Ignore:
Timestamp:
10/01/2015 03:57:53 AM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

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

    r34599 r34730  
    158158     */
    159159    protected $children;
     160
     161    /**
     162     * Whether children have been populated for this comment object.
     163     *
     164     * @since 4.4.0
     165     * @access protected
     166     * @var bool
     167     */
     168    protected $populated_children = false;
    160169
    161170    /**
     
    280289
    281290        if ( is_null( $this->children ) ) {
    282             $this->children = get_comments( $_args );
     291            if ( $this->populated_children ) {
     292                $this->children = array();
     293            } else {
     294                $this->children = get_comments( $_args );
     295            }
    283296        }
    284297
     
    332345
    333346    /**
     347     * Set the 'populated_children' flag.
     348     *
     349     * This flag is important for ensuring that calling `get_children()` on a childless comment will not trigger
     350     * unneeded database queries.
     351     *
     352     * @since 4.4.0
     353     */
     354    public function populated_children( $set ) {
     355        $this->populated_children = (bool) $set;
     356    }
     357
     358    /**
    334359     * Check whether a non-public property is set.
    335360     *
Note: See TracChangeset for help on using the changeset viewer.