Commit 6f89bd36 authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

Use Gitaly for getting Branch/Tag counts

- Backup-rake-spec fixed. Storage config broken
- Use rugged to compare branch/tag-count in specs
- upgrade gitaly
parent ef518df2
...@@ -505,14 +505,10 @@ class Repository ...@@ -505,14 +505,10 @@ class Repository
delegate :tag_names, to: :raw_repository delegate :tag_names, to: :raw_repository
cache_method :tag_names, fallback: [] cache_method :tag_names, fallback: []
def branch_count delegate :branch_count, to: :raw_repository
branches.size
end
cache_method :branch_count, fallback: 0 cache_method :branch_count, fallback: 0
def tag_count delegate :tag_count, to: :raw_repository
raw_repository.rugged.tags.count
end
cache_method :tag_count, fallback: 0 cache_method :tag_count, fallback: 0
def avatar def avatar
......
...@@ -122,6 +122,10 @@ module Gitlab ...@@ -122,6 +122,10 @@ module Gitlab
# Returns the number of valid branches # Returns the number of valid branches
def branch_count def branch_count
Gitlab::GitalyClient.migrate(:branch_names) do |is_enabled|
if is_enabled
gitaly_ref_client.count_branch_names
else
rugged.branches.count do |ref| rugged.branches.count do |ref|
begin begin
ref.name && ref.target # ensures the branch is valid ref.name && ref.target # ensures the branch is valid
...@@ -132,6 +136,19 @@ module Gitlab ...@@ -132,6 +136,19 @@ module Gitlab
end end
end end
end end
end
end
# Returns the number of valid tags
def tag_count
Gitlab::GitalyClient.migrate(:tag_names) do |is_enabled|
if is_enabled
gitaly_ref_client.count_tag_names
else
rugged.tags.count
end
end
end
# Returns an Array of tag names # Returns an Array of tag names
def tag_names def tag_names
......
...@@ -34,6 +34,14 @@ module Gitlab ...@@ -34,6 +34,14 @@ module Gitlab
stub.find_ref_name(request).name stub.find_ref_name(request).name
end end
def count_tag_names
tag_names.count
end
def count_branch_names
branch_names.count
end
private private
def consume_refs_response(response, prefix:) def consume_refs_response(response, prefix:)
......
...@@ -1379,12 +1379,17 @@ describe Repository, models: true do ...@@ -1379,12 +1379,17 @@ describe Repository, models: true do
describe '#branch_count' do describe '#branch_count' do
it 'returns the number of branches' do it 'returns the number of branches' do
expect(repository.branch_count).to be_an(Integer) expect(repository.branch_count).to be_an(Integer)
rugged_count = repository.raw_repository.rugged.branches.count
expect(repository.branch_count).to eq(rugged_count)
end end
end end
describe '#tag_count' do describe '#tag_count' do
it 'returns the number of tags' do it 'returns the number of tags' do
expect(repository.tag_count).to be_an(Integer) expect(repository.tag_count).to be_an(Integer)
# NOTE: Until rugged goes away, make sure rugged and gitaly are in sync
rugged_count = repository.raw_repository.rugged.tags.count
expect(repository.tag_count).to eq(rugged_count)
end end
end end
......
...@@ -230,11 +230,13 @@ describe 'gitlab:app namespace rake task' do ...@@ -230,11 +230,13 @@ describe 'gitlab:app namespace rake task' do
before do before do
FileUtils.mkdir('tmp/tests/default_storage') FileUtils.mkdir('tmp/tests/default_storage')
FileUtils.mkdir('tmp/tests/custom_storage') FileUtils.mkdir('tmp/tests/custom_storage')
gitaly_address = Gitlab.config.repositories.storages.default.gitaly_address
storages = { storages = {
'default' => { 'path' => Settings.absolute('tmp/tests/default_storage') }, 'default' => { 'path' => Settings.absolute('tmp/tests/default_storage'), 'gitaly_address' => gitaly_address },
'custom' => { 'path' => Settings.absolute('tmp/tests/custom_storage') } 'custom' => { 'path' => Settings.absolute('tmp/tests/custom_storage'), 'gitaly_address' => gitaly_address }
} }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
Gitlab::GitalyClient.configure_channels
# Create the projects now, after mocking the settings but before doing the backup # Create the projects now, after mocking the settings but before doing the backup
project_a project_a
......
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