BigW Consortium Gitlab

Commit f8c3a58a by Stan Hu

Avoid Gitaly N+1 calls by caching tag_names

parent 0ea70802
...@@ -221,6 +221,12 @@ class Repository ...@@ -221,6 +221,12 @@ class Repository
branch_names.include?(branch_name) branch_names.include?(branch_name)
end end
def tag_exists?(tag_name)
return false unless raw_repository
tag_names.include?(tag_name)
end
def ref_exists?(ref) def ref_exists?(ref)
!!raw_repository&.ref_exists?(ref) !!raw_repository&.ref_exists?(ref)
rescue ArgumentError rescue ArgumentError
......
...@@ -7,6 +7,8 @@ describe Projects::PipelineSchedulesController do ...@@ -7,6 +7,8 @@ describe Projects::PipelineSchedulesController do
set(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } set(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
describe 'GET #index' do describe 'GET #index' do
render_views
let(:scope) { nil } let(:scope) { nil }
let!(:inactive_pipeline_schedule) do let!(:inactive_pipeline_schedule) do
create(:ci_pipeline_schedule, :inactive, project: project) create(:ci_pipeline_schedule, :inactive, project: project)
......
...@@ -1157,6 +1157,15 @@ describe Repository do ...@@ -1157,6 +1157,15 @@ describe Repository do
end end
end end
describe '#tag_exists?' do
it 'uses tag_names' do
allow(repository).to receive(:tag_names).and_return(['foobar'])
expect(repository.tag_exists?('foobar')).to eq(true)
expect(repository.tag_exists?('master')).to eq(false)
end
end
describe '#branch_names', :use_clean_rails_memory_store_caching do describe '#branch_names', :use_clean_rails_memory_store_caching do
let(:fake_branch_names) { ['foobar'] } let(:fake_branch_names) { ['foobar'] }
......
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