Commit 05a6e2b8 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'backport-rd-5566-improve-performance-of-repository-size-limit-check' into 'master'

Backport some changes from gitlab-ee!5476

See merge request gitlab-org/gitlab-ce!18760
parents bdc1951d 5b584a0f
...@@ -62,6 +62,12 @@ module Gitlab ...@@ -62,6 +62,12 @@ module Gitlab
end end
end end
# Returns an array of Blob instances just with the metadata, that means
# the data attribute has no content.
def batch_metadata(repository, blob_references)
batch(repository, blob_references, blob_size_limit: 0)
end
# Find LFS blobs given an array of sha ids # Find LFS blobs given an array of sha ids
# Returns array of Gitlab::Git::Blob # Returns array of Gitlab::Git::Blob
# Does not guarantee blob data will be set # Does not guarantee blob data will be set
......
...@@ -28,13 +28,14 @@ module Gitlab ...@@ -28,13 +28,14 @@ module Gitlab
# 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee # 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee
def parse(raw_change) def parse(raw_change)
@blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4) @blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4)
@blob_size = @blob_size.to_i
@operation = extract_operation @operation = extract_operation
@old_path, @new_path = extract_paths(raw_paths) @old_path, @new_path = extract_paths(raw_paths)
end end
def extract_paths(file_path) def extract_paths(file_path)
case operation case operation
when :renamed when :copied, :renamed
file_path.split(/\t/) file_path.split(/\t/)
when :deleted when :deleted
[file_path, nil] [file_path, nil]
......
...@@ -579,9 +579,19 @@ module Gitlab ...@@ -579,9 +579,19 @@ module Gitlab
count_commits(from: from, to: to, **options) count_commits(from: from, to: to, **options)
end end
# Counts the amount of commits between `from` and `to`.
def count_commits_between(from, to, options = {})
count_commits(from: from, to: to, **options)
end
# old_rev and new_rev are commit ID's # old_rev and new_rev are commit ID's
# the result of this method is an array of Gitlab::Git::RawDiffChange # the result of this method is an array of Gitlab::Git::RawDiffChange
def raw_changes_between(old_rev, new_rev) def raw_changes_between(old_rev, new_rev)
@raw_changes_between ||= {}
@raw_changes_between[[old_rev, new_rev]] ||= begin
return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA
gitaly_migrate(:raw_changes_between) do |is_enabled| gitaly_migrate(:raw_changes_between) do |is_enabled|
if is_enabled if is_enabled
gitaly_repository_client.raw_changes_between(old_rev, new_rev) gitaly_repository_client.raw_changes_between(old_rev, new_rev)
...@@ -604,6 +614,7 @@ module Gitlab ...@@ -604,6 +614,7 @@ module Gitlab
result result
end end
end end
end
rescue ArgumentError => e rescue ArgumentError => e
raise Gitlab::Git::Repository::GitError.new(e) raise Gitlab::Git::Repository::GitError.new(e)
end end
......
...@@ -251,6 +251,26 @@ describe Gitlab::Git::Blob, seed_helper: true do ...@@ -251,6 +251,26 @@ describe Gitlab::Git::Blob, seed_helper: true do
end end
end end
describe '.batch_metadata' do
let(:blob_references) do
[
[SeedRepo::Commit::ID, "files/ruby/popen.rb"],
[SeedRepo::Commit::ID, 'six']
]
end
subject { described_class.batch_metadata(repository, blob_references) }
it 'returns an empty data attribute' do
first_blob, last_blob = subject
expect(first_blob.data).to be_blank
expect(first_blob.path).to eq("files/ruby/popen.rb")
expect(last_blob.data).to be_blank
expect(last_blob.path).to eq("six")
end
end
describe '.batch_lfs_pointers' do describe '.batch_lfs_pointers' do
let(:tree_object) { repository.rugged.rev_parse('master^{tree}') } let(:tree_object) { repository.rugged.rev_parse('master^{tree}') }
......
...@@ -12,7 +12,7 @@ describe Gitlab::Git::RawDiffChange do ...@@ -12,7 +12,7 @@ describe Gitlab::Git::RawDiffChange do
expect(change.operation).to eq(:unknown) expect(change.operation).to eq(:unknown)
expect(change.old_path).to be_blank expect(change.old_path).to be_blank
expect(change.new_path).to be_blank expect(change.new_path).to be_blank
expect(change.blob_size).to be_blank expect(change.blob_size).to eq(0)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment