diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-19 02:38:34 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-19 02:42:20 +0300 |
commit | 4f9068dfc06269ca7e2247fb0be2796452546de1 (patch) | |
tree | b8a4f61fb70187d1085d7ad0dacf08babf5c3b86 /spec/models/project_spec.rb | |
parent | 02c007bda52ac4cbcc8df98e2faf9273745bf951 (diff) |
Eliminate N+1 queries in LFS file locks checks during a push
This significantly improves performance when a user pushes many references.
project.path_locks.any? doesn't cache the output and runs `SELECT 1 AS one
FROM "path_locks" WHERE project_id = N` each time. When there are thousands
of refs being pushed, this can time out the unicorn worker.
CE port for https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6159.
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index bc9cce6b0c3..a2f8fac2f38 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2339,6 +2339,22 @@ describe Project do end end + describe '#any_lfs_file_locks?', :request_store do + set(:project) { create(:project) } + + it 'returns false when there are no LFS file locks' do + expect(project.any_lfs_file_locks?).to be_falsey + end + + it 'returns a cached true when there are LFS file locks' do + create(:lfs_file_lock, project: project) + + expect(project.lfs_file_locks).to receive(:any?).once.and_call_original + + 2.times { expect(project.any_lfs_file_locks?).to be_truthy } + end + end + describe '#protected_for?' do let(:project) { create(:project) } |