From 3a4169d7abe25dafc676eee6668d2d1851882c6b Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 30 Aug 2016 14:48:29 +0000 Subject: [PATCH] Comments: Don't do direct SQL query when fetching decendants. The SQL query was built using the clauses compiled when querying for top-level comments. But in cases where the top-level comment query results are already in the cache, the SQL clauses are not built, and so are unavailable for `fill_descendants()`. Instead, we call `get_comments()`, using modified versions of the parameters passed to the main `WP_Comment_Query` class. Props Akeif, Rarst for testing. Fixes #37696. Built from https://develop.svn.wordpress.org/trunk@38446 git-svn-id: http://core.svn.wordpress.org/trunk@38387 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-comment-query.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-comment-query.php b/wp-includes/class-wp-comment-query.php index 715f0aae8d..573115a952 100644 --- a/wp-includes/class-wp-comment-query.php +++ b/wp-includes/class-wp-comment-query.php @@ -990,8 +990,16 @@ class WP_Comment_Query { } if ( $uncached_parent_ids ) { - $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $uncached_parent_ids ) ) . ')'; - $level_comments = $this->db->get_results( "SELECT {$this->db->comments}.comment_ID, {$this->db->comments}.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" ); + // Fetch this level of comments. + $parent_query_args = $this->query_vars; + foreach ( $exclude_keys as $exclude_key ) { + $parent_query_args[ $exclude_key ] = ''; + } + $parent_query_args['parent__in'] = $uncached_parent_ids; + $parent_query_args['no_found_rows'] = true; + $parent_query_args['hierarchical'] = false; + + $level_comments = get_comments( $parent_query_args ); // Cache parent-child relationships. $parent_map = array_fill_keys( $uncached_parent_ids, array() ); diff --git a/wp-includes/version.php b/wp-includes/version.php index ff4e15d064..b6e5ea8f6f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38445'; +$wp_version = '4.7-alpha-38446'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.