Commit 3346106b authored by Markus Koller's avatar Markus Koller

Remove container indirection in Blob.lazy

When working with wiki repositories, we end up doing
`container.project.repository` and using the main project repository,
rather than the original wiki repository.

Since `Blob.lazy` doesn't use the `container` we can just pass the
`Repository` instance directly.
parent b9c745f0
...@@ -86,8 +86,8 @@ class Blob < SimpleDelegator ...@@ -86,8 +86,8 @@ class Blob < SimpleDelegator
new(blob, container) new(blob, container)
end end
def self.lazy(container, commit_id, path, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) def self.lazy(repository, 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| 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| args[:key].blobs_at(items, blob_size_limit: blob_size_limit).each do |blob|
loader.call([blob.commit_id, blob.path], blob) if blob loader.call([blob.commit_id, blob.path], blob) if blob
end end
......
...@@ -204,7 +204,7 @@ class Snippet < ApplicationRecord ...@@ -204,7 +204,7 @@ class Snippet < ApplicationRecord
def blobs def blobs
return [] unless repository_exists? 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 end
def hook_attrs def hook_attrs
......
...@@ -357,7 +357,7 @@ module Gitlab ...@@ -357,7 +357,7 @@ module Gitlab
def fetch_blob(sha, path) def fetch_blob(sha, path)
return unless sha return unless sha
Blob.lazy(repository.project, sha, path) Blob.lazy(repository, sha, path)
end end
def total_blob_lines(blob) def total_blob_lines(blob)
......
...@@ -32,7 +32,7 @@ describe Blob do ...@@ -32,7 +32,7 @@ describe Blob do
it 'does not fetch blobs when none are accessed' do it 'does not fetch blobs when none are accessed' do
expect(container.repository).not_to receive(:blobs_at) expect(container.repository).not_to receive(:blobs_at)
described_class.lazy(container, commit_id, 'CHANGELOG') described_class.lazy(container.repository, commit_id, 'CHANGELOG')
end end
it 'fetches all blobs for the same repository when one is accessed' do it 'fetches all blobs for the same repository when one is accessed' do
...@@ -41,10 +41,10 @@ describe Blob do ...@@ -41,10 +41,10 @@ describe Blob do
.once.and_call_original .once.and_call_original
expect(other_container.repository).not_to receive(:blobs_at) expect(other_container.repository).not_to receive(:blobs_at)
changelog = described_class.lazy(container, commit_id, 'CHANGELOG') changelog = described_class.lazy(container.repository, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container, commit_id, 'CONTRIBUTING.md') 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 # Access property so the values are loaded
changelog.id changelog.id
...@@ -52,14 +52,14 @@ describe Blob do ...@@ -52,14 +52,14 @@ describe Blob do
end end
it 'does not include blobs from previous requests in later requests' do it 'does not include blobs from previous requests in later requests' do
changelog = described_class.lazy(container, commit_id, 'CHANGELOG') changelog = described_class.lazy(container.repository, commit_id, 'CHANGELOG')
contributing = described_class.lazy(same_container, commit_id, 'CONTRIBUTING.md') contributing = described_class.lazy(same_container.repository, commit_id, 'CONTRIBUTING.md')
# Access property so the values are loaded # Access property so the values are loaded
changelog.id changelog.id
contributing.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) expect(container.repository).to receive(:blobs_at)
.with([[commit_id, 'README.md']], blob_size_limit: blob_size_limit).once.and_call_original .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