From f8c3a58a54d622193a0cf15777a0d0631289278c Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 8 Dec 2017 22:20:28 -0800 Subject: [PATCH] Avoid Gitaly N+1 calls by caching tag_names --- app/models/repository.rb | 6 ++++++ .../projects/pipeline_schedules_controller_spec.rb | 2 ++ spec/models/repository_spec.rb | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/app/models/repository.rb b/app/models/repository.rb index c0e31eca8da..2413e60bc76 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -221,6 +221,12 @@ class Repository branch_names.include?(branch_name) end + def tag_exists?(tag_name) + return false unless raw_repository + + tag_names.include?(tag_name) + end + def ref_exists?(ref) !!raw_repository&.ref_exists?(ref) rescue ArgumentError diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index debc20ee467..8888573e882 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -7,6 +7,8 @@ describe Projects::PipelineSchedulesController do set(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } describe 'GET #index' do + render_views + let(:scope) { nil } let!(:inactive_pipeline_schedule) do create(:ci_pipeline_schedule, :inactive, project: project) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 129fce74f45..08eb563082f 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1157,6 +1157,15 @@ describe Repository do 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 let(:fake_branch_names) { ['foobar'] }