diff options
author | Rubén Dávila <ruben@gitlab.com> | 2018-06-06 13:49:38 -0500 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2018-06-06 13:49:38 -0500 |
commit | 29818672e12fe779034920933098f47269fdef16 (patch) | |
tree | b71983e6a7909a81294e14be777fe7b8bd9e102b /spec/lib/gitlab/git/blob_spec.rb | |
parent | 90a5bcc5c9bcf90b4eb17ace072212335b85ea29 (diff) | |
download | gitlab-ce-rd-45062-further-improve-lfs-integrity-check-performance.tar.gz |
Improve performance used to check LFS integrityrd-45062-further-improve-lfs-integrity-check-performance
Instead of using `git rev-list` and loading each Blob to inspect its
content, we're now relying on the usage of `git diff` and `git
cat-file`. This has the main advantage
that we're reusing the same technique used for other existing checks,
hence all the Blobs are cached.
Diffstat (limited to 'spec/lib/gitlab/git/blob_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git/blob_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index 94eaf86ef80..796dabf7d0e 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -277,6 +277,67 @@ describe Gitlab::Git::Blob, seed_helper: true do end end + describe '.lfs_pointers_between' do + let(:repository) { create(:project, :repository).repository } + let(:old_rev) { Gitlab::Git::EMPTY_TREE_ID } + let(:lfs_rev) { TestEnv::BRANCH_SHA['lfs'] } + let(:non_lfs_rev) { TestEnv::BRANCH_SHA['feature'] } + + context 'with LFS objects' do + it 'returns a list of Gitlab::Git::Blob' do + blobs = described_class.lfs_pointers_between(repository, old_rev, lfs_rev) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + expect(blobs).to be_an(Array) + end + + context 'when changes consist of a single LFS pointer' do + let(:parent_commit) { '5f923865dde3436854e9ceb9cdb7815618d4e849' } + let(:commit_with_lfs_pointer) { '048721d90c449b244b7b4c53a9186b04330174ec' } + + it 'returns the single LFS pointer found' do + blobs = described_class.lfs_pointers_between(repository, parent_commit, commit_with_lfs_pointer) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + end + end + end + + context 'without LFS objects' do + it 'returns an empty Array' do + blobs = described_class.lfs_pointers_between(repository, old_rev, non_lfs_rev) + + expect(blobs).to eq([]) + end + end + end + + describe '.lfs_pointers_from_tree' do + let(:repository) { create(:project, :repository).repository } + let(:tree_with_lfs_objects) { repository.tree('lfs', 'files/lfs') } + let(:tree_without_lfs_objects) { repository.tree('feature', '/') } + + context 'with a tree with LFS objects' do + it 'returns a list of Gitlab::Git::Blob' do + blobs = described_class.lfs_pointers_from_tree(repository, tree_with_lfs_objects) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + expect(blobs).to be_an(Array) + end + end + + context 'with a tree without LFS objects' do + it 'returns an empty Array' do + blobs = described_class.lfs_pointers_from_tree(repository, tree_without_lfs_objects) + + expect(blobs).to eq([]) + end + end + end + describe '.batch_lfs_pointers' do let(:tree_object) { repository.rugged.rev_parse('master^{tree}') } |