diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-26 13:20:49 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-26 13:20:49 +0000 |
commit | 1c1b7a820db168974289039acd9f1f89664b684e (patch) | |
tree | 84c89e3ec02b2b2629064f093f3806d123424bd5 /spec | |
parent | f9c6134b60465a5628c36d396e7f81f04c3ea235 (diff) | |
parent | 4b7e9eaacd3c5ecfb6e8e28a0d36832d1627515a (diff) | |
download | gitlab-ce-1c1b7a820db168974289039acd9f1f89664b684e.tar.gz |
Merge branch 'dm-batch-loader-key' into 'master'
Batch load only data from same repository when lazy object is accessed
See merge request gitlab-org/gitlab-ce!23309
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/git/commit_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/git/tag_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/blob_spec.rb | 21 |
3 files changed, 24 insertions, 6 deletions
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 74d542060d5..db68062e433 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -450,11 +450,17 @@ describe Gitlab::Git::Commit, :seed_helper do described_class.extract_signature_lazily(repository, commit_id) end + other_repository = double(:repository) + described_class.extract_signature_lazily(other_repository, commit_ids.first) + expect(described_class).to receive(:batch_signature_extraction) .with(repository, commit_ids) .once .and_return({}) + expect(described_class).not_to receive(:batch_signature_extraction) + .with(other_repository, commit_ids.first) + 2.times { signatures.each(&:itself) } end end diff --git a/spec/lib/gitlab/git/tag_spec.rb b/spec/lib/gitlab/git/tag_spec.rb index abee2822d77..b51e3879f49 100644 --- a/spec/lib/gitlab/git/tag_spec.rb +++ b/spec/lib/gitlab/git/tag_spec.rb @@ -38,6 +38,9 @@ describe Gitlab::Git::Tag, :seed_helper do end it 'gets messages in one batch', :request_store do + other_repository = double(:repository) + described_class.get_message(other_repository, tag_ids.first) + expect { subject.map(&:itself) }.to change { Gitlab::GitalyClient.get_request_count }.by(1) end end 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 |