summaryrefslogtreecommitdiff
path: root/spec/models/merge_request_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-11-02 11:27:01 -0700
committerStan Hu <stanhu@gmail.com>2018-11-02 12:11:30 -0700
commitdbc03ce3a9db7f8c3d29f657beccd839d515e384 (patch)
tree8149327bf0c2b970f07e6a54536db68ae3cb4bb4 /spec/models/merge_request_spec.rb
parent6f12e3929df987e49427a1355cdf35798f97da65 (diff)
downloadgitlab-ce-dbc03ce3a9db7f8c3d29f657beccd839d515e384.tar.gz
Optimize merge request refresh by using the database to check commit SHAssh-optimize-mr-commit-sha-lookup
Previously for a given merge request, we would: 1. Create the array of commit SHAs involved in the push (A) 2. Request all merge request commits and map the SHA (B) 3. Reload the diff if there were any common commits between A and B We can avoid additional database querying and overhead by checking with the database whether the merge request contains any of the commit SHAs. Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/53213
Diffstat (limited to 'spec/models/merge_request_spec.rb')
-rw-r--r--spec/models/merge_request_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 7d500f9e579..2eb5e39ccfd 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -2611,6 +2611,32 @@ describe MergeRequest do
end
end
+ describe '#includes_any_commits?' do
+ it 'returns false' do
+ expect(subject.includes_any_commits?([Gitlab::Git::BLANK_SHA])).to be_falsey
+ end
+
+ it 'returns true' do
+ expect(subject.includes_any_commits?([subject.merge_request_diff.head_commit_sha])).to be_truthy
+ end
+
+ it 'returns true even when there is a non-existent comit' do
+ expect(subject.includes_any_commits?([Gitlab::Git::BLANK_SHA, subject.merge_request_diff.head_commit_sha])).to be_truthy
+ end
+
+ context 'unpersisted merge request' do
+ let(:new_mr) { build(:merge_request) }
+
+ it 'returns false' do
+ expect(new_mr.includes_any_commits?([Gitlab::Git::BLANK_SHA])).to be_falsey
+ end
+
+ it 'returns true' do
+ expect(new_mr.includes_any_commits?([subject.merge_request_diff.head_commit_sha])).to be_truthy
+ end
+ end
+ end
+
describe '#can_allow_collaboration?' do
let(:target_project) { create(:project, :public) }
let(:source_project) { fork_project(target_project) }