Use branch_count in Repository#has_visible_content?

Gitlab::Git::Repository#branch_count is a tad faster than the previous
setup. See gitlab-org/gitlab_git!62 for more information.
This commit is contained in:
Yorick Peterse 2016-01-21 18:19:18 +01:00
parent d21d8e57d3
commit 0689663487
2 changed files with 21 additions and 1 deletions

View File

@ -57,7 +57,7 @@ class Repository
# This method return true if repository contains some content visible in project page.
#
def has_visible_content?
!raw_repository.branches.empty?
raw_repository.branch_count > 0
end
def commit(id = 'HEAD')

View File

@ -219,4 +219,24 @@ describe Repository, models: true do
end
end
end
describe '#has_visible_content?' do
subject { repository.has_visible_content? }
describe 'when there are no branches' do
before do
allow(repository.raw_repository).to receive(:branch_count).and_return(0)
end
it { is_expected.to eq(false) }
end
describe 'when there are branches' do
before do
allow(repository.raw_repository).to receive(:branch_count).and_return(3)
end
it { is_expected.to eq(true) }
end
end
end