diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-03 13:31:41 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-05 02:39:33 +0300 |
commit | cbc20d2b7f8c73e2892c0c458619df2a9fe0c9ab (patch) | |
tree | 5f99239e63863d4631fe46c44363ee703c3b2a37 /doc/development/query_recorder.md | |
parent | fe0ebf76c49e2512b211c5d43152275c536f7e3a (diff) |
Remove N+1 query for author in issues API
This was being masked by the statement cache because only one author was used
per issue in the test..
Also adds support for an Rspec matcher `exceed_all_query_limit`.
Diffstat (limited to 'doc/development/query_recorder.md')
-rw-r--r-- | doc/development/query_recorder.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/development/query_recorder.md b/doc/development/query_recorder.md index 26d3355e94d..61e5e1afede 100644 --- a/doc/development/query_recorder.md +++ b/doc/development/query_recorder.md @@ -22,6 +22,19 @@ As an example you might create 5 issues in between counts, which would cause the > **Note:** In some cases the query count might change slightly between runs for unrelated reasons. In this case you might need to test `exceed_query_limit(control_count + acceptable_change)`, but this should be avoided if possible. +## Cached queries + +By default, QueryRecorder will ignore cached queries in the count. However, it may be better to count +all queries to avoid introducing an N+1 query that may be masked by the statement cache. To do this, +pass the `skip_cached` variable to `QueryRecorder` and use the `exceed_all_query_limit` matcher: + +it "avoids N+1 database queries" do + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { visit_some_page }.count + create_list(:issue, 5) + expect { visit_some_page }.not_to exceed_all_query_limit(control_count) +end +``` + ## Finding the source of the query It may be useful to identify the source of the queries by looking at the call backtrace. |