-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add caching to comment feeds #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f2a72b5
c345ebb
295b89c
2f9e17d
108ff23
bba3fab
f65d588
e51b35f
d484ab9
ece6c30
ff1fc0f
e7e08b2
d261900
436af7a
1aaec71
3e9cc15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @group query | ||
spacedmonkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @group comments | ||
| * @group feeds | ||
| */ | ||
| class Tests_Query_CommentFeed extends WP_UnitTestCase { | ||
| public static $post_type = 'post'; | ||
| protected static $post_ids = array(); | ||
|
|
||
| public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | ||
| self::$post_ids = $factory->post->create_many( | ||
| 3, | ||
| array( | ||
| 'post_type' => self::$post_type, | ||
| 'post_status' => 'publish', | ||
| ) | ||
| ); | ||
| foreach ( self::$post_ids as $post_id ) { | ||
| $factory->comment->create_post_comments( $post_id, 5 ); | ||
| } | ||
|
|
||
| update_option( 'posts_per_rss', 100 ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 36904 | ||
| */ | ||
| public function test_archive_comment_feed() { | ||
| global $wpdb; | ||
| add_filter( 'split_the_query', '__return_false' ); | ||
spacedmonkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $q1 = new WP_Query(); | ||
| $args = array( | ||
| 'withcomments' => 1, | ||
| 'feed' => 'comments-rss', | ||
| 'post_type' => self::$post_type, | ||
| 'update_post_meta_cache' => false, | ||
| 'update_post_term_cache' => false, | ||
| 'ignore_sticky_posts' => false, | ||
| 'no_found_rows' => true, | ||
| ); | ||
| $q1->query( $args ); | ||
| $num_queries = $wpdb->num_queries; | ||
| $q2 = new WP_Query(); | ||
| $q2->query( $args ); | ||
| $this->assertTrue( $q2->is_comment_feed() ); | ||
| $this->assertFalse( $q2->is_singular() ); | ||
|
Comment on lines
+47
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd split these in to separate tests, basically:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand the need to split these tests up? Can you explain why we would have that overhead?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, there will be a small amount of overhead but the use of shared fixtures in The reason I suggested splitting them up (or at least doing so differently) is that it will provide more information to developers if something is broken. In this test, if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not about fixtures, it is about what we are testing. We are testing the cache, checking that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
| $this->assertSame( $num_queries + 1, $wpdb->num_queries ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 36904 | ||
| */ | ||
| public function test_archive_comment_feed_invalid_cache() { | ||
| $q1 = new WP_Query(); | ||
| $args = array( | ||
| 'withcomments' => 1, | ||
| 'feed' => 'comments-rss', | ||
| 'post_type' => self::$post_type, | ||
| 'update_post_meta_cache' => false, | ||
| 'update_post_term_cache' => false, | ||
| 'ignore_sticky_posts' => false, | ||
| ); | ||
| $q1->query( $args ); | ||
| $comment_count = $q1->comment_count; | ||
| $this->assertSame( 15, $comment_count ); | ||
|
|
||
| $post = self::factory()->post->create_and_get( | ||
| array( | ||
| 'post_type' => self::$post_type, | ||
| 'post_status' => 'publish', | ||
| ) | ||
| ); | ||
| self::factory()->comment->create_post_comments( $post->ID, 5 ); | ||
| $q2 = new WP_Query(); | ||
| $q2->query( $args ); | ||
| $this->assertTrue( $q2->is_comment_feed() ); | ||
| $this->assertFalse( $q2->is_singular() ); | ||
|
|
||
| $comment_count = $q2->comment_count; | ||
| $this->assertSame( 20, $comment_count ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 36904 | ||
| */ | ||
| public function test_single_comment_feed() { | ||
| global $wpdb; | ||
| $post = get_post( self::$post_ids[0] ); | ||
|
|
||
| $q1 = new WP_Query(); | ||
| $args = array( | ||
| 'withcomments' => 1, | ||
| 'feed' => 'comments-rss', | ||
| 'post_type' => $post->post_type, | ||
| 'name' => $post->post_name, | ||
| 'update_post_meta_cache' => false, | ||
| 'update_post_term_cache' => false, | ||
| 'ignore_sticky_posts' => false, | ||
| ); | ||
|
|
||
| $q1->query( $args ); | ||
| $num_queries = $wpdb->num_queries; | ||
| $q2 = new WP_Query(); | ||
| $q2->query( $args ); | ||
|
|
||
| $this->assertTrue( $q2->is_comment_feed() ); | ||
| $this->assertTrue( $q2->is_singular() ); | ||
| $this->assertSame( $num_queries + 1, $wpdb->num_queries ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.