From 3ec4faf6e3ac136b13d1622b760e222e87b455de Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 5 Feb 2016 18:35:47 +0000 Subject: [PATCH] Comments: Add 'parent__in' and 'parent__not_in' to query var defaults. Query var defaults are used to calculate a cache key. The fact that these params were not listed among the defaults was causing cache keys to be insufficiently specific. Props danielbachhuber. Fixes #35677. git-svn-id: https://develop.svn.wordpress.org/trunk@36479 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-comment-query.php | 2 ++ tests/phpunit/tests/comment/query.php | 38 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index 71cd525833..df1bbaf2ef 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -273,6 +273,8 @@ class WP_Comment_Query { 'orderby' => '', 'order' => 'DESC', 'parent' => '', + 'parent__in' => '', + 'parent__not_in' => '', 'post_author__in' => '', 'post_author__not_in' => '', 'post_ID' => '', diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index c717c83cb8..bda344cd95 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -1864,6 +1864,44 @@ class Tests_Comment_Query extends WP_UnitTestCase { $this->assertSame( $num_queries, $wpdb->num_queries ); } + /** + * @ticket 35677 + */ + public function test_cache_should_be_sensitive_to_parent__in() { + global $wpdb; + + $q1 = new WP_Comment_Query( array( + 'parent__in' => array( 1, 2, 3 ), + ) ); + + $num_queries = $wpdb->num_queries; + + $q2 = new WP_Comment_Query( array( + 'parent__in' => array( 4, 5, 6 ), + ) ); + + $this->assertNotEquals( $num_queries, $wpdb->num_queries ); + } + + /** + * @ticket 35677 + */ + public function test_cache_should_be_sensitive_to_parent__not_in() { + global $wpdb; + + $q1 = new WP_Comment_Query( array( + 'parent__not_in' => array( 1, 2, 3 ), + ) ); + + $num_queries = $wpdb->num_queries; + + $q2 = new WP_Comment_Query( array( + 'parent__not_in' => array( 4, 5, 6 ), + ) ); + + $this->assertNotEquals( $num_queries, $wpdb->num_queries ); + } + /** * @ticket 32762 */