Commit 0bbc7a8c authored by James Lopez's avatar James Lopez

Merge branch 'blob-lazy-project-coupling' into 'master'

Remove container indirection in Blob.lazy

See merge request gitlab-org/gitlab!32319
parents 32accbec 3346106b
......@@ -86,8 +86,8 @@ class Blob < SimpleDelegator
new(blob, container)
end
def self.lazy(container, commit_id, path, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE)
BatchLoader.for([commit_id, path]).batch(key: container.repository) do |items, loader, args|
def self.lazy(repository, commit_id, path, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE)
BatchLoader.for([commit_id, path]).batch(key: repository) do |items, loader, args|
args[:key].blobs_at(items, blob_size_limit: blob_size_limit).each do |blob|
loader.call([blob.commit_id, blob.path], blob) if blob
end
......
......@@ -204,7 +204,7 @@ class Snippet < ApplicationRecord
def blobs
return [] unless repository_exists?
repository.ls_files(repository.root_ref).map { |file| Blob.lazy(self, repository.root_ref, file) }
repository.ls_files(repository.root_ref).map { |file| Blob.lazy(repository, repository.root_ref, file) }
end
def hook_attrs
......
......@@ -357,7 +357,7 @@ module Gitlab
def fetch_blob(sha, path)
return unless sha
Blob.lazy(repository.project, sha, path)
Blob.lazy(repository, sha, path)
end
def total_blob_lines(blob)
......
......@@ -32,7 +32,7 @@ describe Blob do
it 'does not fetch blobs when none are accessed' do
expect(container.repository).not_to receive(:blobs_at)
described_class.lazy(container, commit_id, 'CHANGELOG')
described_class.lazy(container.repository, commit_id, 'CHANGELOG')
end
it 'fetches all blobs for the same repository when one is accessed' do
......@@ -41,10 +41,10 @@ describe Blob do
.once.and_call_original
expect(other_container.repository).not_to receive(:blobs_at)
changelog = described_class.lazy(container, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container, commit_id, 'CONTRIBUTING.md')
changelog = described_class.lazy(container.repository, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container.repository, commit_id, 'CONTRIBUTING.md')
described_class.lazy(other_container, commit_id, 'CHANGELOG')
described_class.lazy(other_container.repository, commit_id, 'CHANGELOG')
# Access property so the values are loaded
changelog.id
......@@ -52,14 +52,14 @@ describe Blob do
end
it 'does not include blobs from previous requests in later requests' do
changelog = described_class.lazy(container, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container, commit_id, 'CONTRIBUTING.md')
changelog = described_class.lazy(container.repository, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container.repository, commit_id, 'CONTRIBUTING.md')
# Access property so the values are loaded
changelog.id
contributing.id
readme = described_class.lazy(container, commit_id, 'README.md')
readme = described_class.lazy(container.repository, commit_id, 'README.md')
expect(container.repository).to receive(:blobs_at)
.with([[commit_id, 'README.md']], blob_size_limit: blob_size_limit).once.and_call_original
......
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