summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-03-20 15:51:54 +0000
committerSean McGivern <sean@gitlab.com>2018-03-21 17:24:46 +0000
commit39c9928cfbf5b72042755c58bd5c484551c5f1ad (patch)
tree02d8de7ece39fa76039e4a640ada9fef147bc94d /spec
parent398f13f39a0ce51c9ca3f223e87df88db822a396 (diff)
downloadgitlab-ce-39c9928cfbf5b72042755c58bd5c484551c5f1ad.tar.gz
Fix N+1 in `MergeRequest#merge_request_diff_for`reduce-query-count-for-mergerequestscontroller-show
Previously, this would issue a query for each unique `diff_refs_or_sha` passed. This was because we didn't want to load other MR diffs into memory, as they had some very large columns. Now they are actually very small, and it's more efficient to just load them all at once and do the finding in Ruby.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/merge_request_spec.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index ff5a6f63010..f73f44ca0ad 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1961,6 +1961,17 @@ describe MergeRequest do
expect(subject.merge_request_diff_for(merge_request_diff3.head_commit_sha)).to eq(merge_request_diff3)
end
end
+
+ it 'runs a single query on the initial call, and none afterwards' do
+ expect { subject.merge_request_diff_for(merge_request_diff1.diff_refs) }
+ .not_to exceed_query_limit(1)
+
+ expect { subject.merge_request_diff_for(merge_request_diff2.diff_refs) }
+ .not_to exceed_query_limit(0)
+
+ expect { subject.merge_request_diff_for(merge_request_diff3.head_commit_sha) }
+ .not_to exceed_query_limit(0)
+ end
end
describe '#version_params_for' do