Skip to content
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

MONGOID-4521 Ensure that QueryCache doesn't cache multi-batch results #4490

Merged
merged 3 commits into from Sep 24, 2018

Conversation

saghm
Copy link
Contributor

@saghm saghm commented Apr 12, 2018

No description provided.

@saghm saghm requested a review from estolfo April 12, 2018 21:01
@@ -414,15 +414,15 @@
context "when querying a very large collection" do

before do
123.times { Band.create! }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change?

Copy link
Contributor Author

@saghm saghm Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this pull request is to disable the query cache for queries greater than one batch. Since the default batch size is less than 123, this test wouldn't actually test the query cache.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is labeled "very large collection", sounds like it should be changed to "a collection with size less than batch size" and possibly there is already a context like that elsewhere in the file.


context 'when the initial query does not exhaust the results' do
before do
Mongoid::QueryCache.enabled = true
Copy link
Contributor

@simi simi Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually it is good idea to temporarily enable config option and restore original state once test is done (for example using around block) to not leak this change to another test env (often resulting into random failing tests).

around(:each) do |example|
query_cache_enabled = Mongoid::QueryCache.enabled?
Mongoid::QueryCache.enabled = true
example.run
Mongoid::QueryCache.enabled = query_cache_enabled
end

Copy link
Contributor Author

@saghm saghm Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that at the top of the description block, there is already an around block defined:

around do |spec|
  Mongoid::QueryCache.clear_cache
  Mongoid::QueryCache.cache { spec.run }
end

The implementation of QueryCache.cache already saves the value from before the passed block and restores it after.


it 'does not cache the result' do
expect(Band.all.map(&:id).size).to eq(10)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is good but there should be another one setting batch size to 4 at query time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what that has to do with the query cache; is the idea to do a query with the same batch size as the number of results of the previous query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, as discussed offline

@saghm saghm merged commit 700a7a7 into mongodb:master Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants