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:
authorDouwe Maan <douwe@selenight.nl>2018-11-23 14:26:17 +0300
committerDouwe Maan <douwe@selenight.nl>2018-11-26 13:15:18 +0300
commit5f0e4040ce7d4d0019b3340dd603cc6f67dd036d (patch)
tree76fb16a30e6ea702ecc14164e9b1c4d277ac1920 /spec/models/blob_spec.rb
parentba9eeea4ee2eb3a43cc3d107a2590a6227af89ed (diff)
Batch load only data from same repository when lazy object is accessed
By specifying `key`, we get a different lazy batch loader for each repository, which means that accessing a lazy object from one repository will only result in that repository's objects being fetched, not those of other repositories, saving us some unnecessary Gitaly lookups.
Diffstat (limited to 'spec/models/blob_spec.rb')
-rw-r--r--spec/models/blob_spec.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb
index 81e35e6c931..ed93f94d893 100644
--- a/spec/models/blob_spec.rb
+++ b/spec/models/blob_spec.rb
@@ -18,14 +18,23 @@ describe Blob do
describe '.lazy' do
let(:project) { create(:project, :repository) }
- let(:commit) { project.commit_by(oid: 'e63f41fe459e62e1228fcef60d7189127aeba95a') }
+ let(:other_project) { create(:project, :repository) }
+ let(:commit_id) { 'e63f41fe459e62e1228fcef60d7189127aeba95a' }
- it 'fetches all blobs when the first is accessed' do
- changelog = described_class.lazy(project, commit.id, 'CHANGELOG')
- contributing = described_class.lazy(project, commit.id, 'CONTRIBUTING.md')
+ it 'does not fetch blobs when none are accessed' do
+ expect(project.repository).not_to receive(:blobs_at)
- expect(Gitlab::Git::Blob).to receive(:batch).once.and_call_original
- expect(Gitlab::Git::Blob).not_to receive(:find)
+ described_class.lazy(project, commit_id, 'CHANGELOG')
+ end
+
+ it 'fetches all blobs for the same repository when one is accessed' do
+ expect(project.repository).to receive(:blobs_at).with([[commit_id, 'CHANGELOG'], [commit_id, 'CONTRIBUTING.md']]).once.and_call_original
+ expect(other_project.repository).not_to receive(:blobs_at)
+
+ changelog = described_class.lazy(project, commit_id, 'CHANGELOG')
+ contributing = described_class.lazy(project, commit_id, 'CONTRIBUTING.md')
+
+ described_class.lazy(other_project, commit_id, 'CHANGELOG')
# Access property so the values are loaded
changelog.id