diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-01-05 10:47:28 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-01-05 10:47:28 +0000 |
commit | 3bb68efb7acc8b39bf996901fe89651d198b54d3 (patch) | |
tree | 07bf36db922d0450f30e43922974791da1a8bfa6 /lib | |
parent | 4dd0c55f059154a8d866a16e4753212895061024 (diff) | |
parent | 6b15784ce7d893ed509c00d9f51a4702787799ed (diff) | |
download | gitlab-ce-3bb68efb7acc8b39bf996901fe89651d198b54d3.tar.gz |
Merge branch 'zj-blob-batch' into 'master'
Reroute batch blobs to single blob RPC
See merge request gitlab-org/gitlab-ce!16082
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/blob.rb | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 228d97a87ab..a1755143abe 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -50,10 +50,19 @@ module Gitlab # to the caller to limit the number of blobs and blob_size_limit. # # Gitaly migration issue: https://gitlab.com/gitlab-org/gitaly/issues/798 - def batch(repository, blob_references, blob_size_limit: nil) - blob_size_limit ||= MAX_DATA_DISPLAY_SIZE - blob_references.map do |sha, path| - find_by_rugged(repository, sha, path, limit: blob_size_limit) + def batch(repository, blob_references, blob_size_limit: MAX_DATA_DISPLAY_SIZE) + Gitlab::GitalyClient.migrate(:list_blobs_by_sha_path) do |is_enabled| + if is_enabled + Gitlab::GitalyClient.allow_n_plus_1_calls do + blob_references.map do |sha, path| + find_by_gitaly(repository, sha, path, limit: blob_size_limit) + end + end + else + blob_references.map do |sha, path| + find_by_rugged(repository, sha, path, limit: blob_size_limit) + end + end end end @@ -122,13 +131,23 @@ module Gitlab ) end - def find_by_gitaly(repository, sha, path) + def find_by_gitaly(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) path = path.sub(/\A\/*/, '') path = '/' if path.empty? name = File.basename(path) - entry = Gitlab::GitalyClient::CommitService.new(repository).tree_entry(sha, path, MAX_DATA_DISPLAY_SIZE) + + # Gitaly will think that setting the limit to 0 means unlimited, while + # the client might only need the metadata and thus set the limit to 0. + # In this method we'll then set the limit to 1, but clear the byte of data + # that we got back so for the outside world it looks like the limit was + # actually 0. + req_limit = limit == 0 ? 1 : limit + + entry = Gitlab::GitalyClient::CommitService.new(repository).tree_entry(sha, path, req_limit) return unless entry + entry.data = "" if limit == 0 + case entry.type when :COMMIT new( |