Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-07-13 13:57:48 +0300
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-07-16 14:00:58 +0300
commite78968dd0ed7d1df2f6bde510c2c887fdce8b03e (patch)
treedd0e6a4a98bd402fc28d1b9928cbc3f3f41469c8
parentc2a0a3ab1aed9814c1044c753b3f31b29b6142b1 (diff)
Memoize commit lookups between ChangeAccess callsjej/memoize-change-access-commits
-rw-r--r--app/models/repository.rb10
-rw-r--r--spec/lib/gitlab/git_access_spec.rb20
2 files changed, 27 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 5ed2a7b4068..c169f29a99d 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -153,13 +153,17 @@ class Repository
end
# Returns a list of commits that are not present in any reference
+ # Uses commit_by to memoize commits between method calls
def new_commits(newrev)
+ new_commit_shas(newrev).map { |sha| commit_by(oid: sha.strip) }
+ end
+
+ # Returns a list of commit shas that are not present in any reference
+ def new_commit_shas(newrev)
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/1233
- refs = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
+ Gitlab::GitalyClient::StorageSettings.allow_disk_access do
::Gitlab::Git::RevList.new(raw, newrev: newrev).new_refs
end
-
- refs.map { |sha| commit(sha.strip) }
end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/384
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb
index 6d11efb42c8..3d78c18361a 100644
--- a/spec/lib/gitlab/git_access_spec.rb
+++ b/spec/lib/gitlab/git_access_spec.rb
@@ -943,6 +943,26 @@ describe Gitlab::GitAccess do
# There is still an N+1 query with protected branches
expect { access.check('git-receive-pack', changes) }.not_to exceed_query_limit(control_count).with_threshold(1)
end
+
+ context 'with multiple changes' do
+ let(:changes) do
+ [
+ "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/first",
+ "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/second"
+ ]
+ end
+
+ it 'caches commit lookups across changes' do
+ stub_lfs_setting(enabled: true)
+ create(:lfs_file_lock, user: create(:user), project: project, path: 'README')
+ allow(project.repository).to receive(:new_commit_shas) { ["b83d6e391c22777fca1ed3012fce84f633d7fed0"] }
+ #, "498214de67004b1da3d820901307bed2a68a8ef6"] }
+
+ expect(Gitlab::Git::Commit).to receive(:find).once.and_call_original
+
+ access.check('git-receive-pack', changes)
+ end
+ end
end
end