diff --git a/ee/app/finders/geo/repository_verification_finder.rb b/ee/app/finders/geo/repository_verification_finder.rb index 7280214edc54bb263b81e51edd02bfbea5a955f4..0317b55bba2ee9239a4a7838b5dccf7e5ad12098 100644 --- a/ee/app/finders/geo/repository_verification_finder.rb +++ b/ee/app/finders/geo/repository_verification_finder.rb @@ -61,19 +61,19 @@ def find_reverifiable_wikis(interval:, batch_size:) end def count_verified_repositories - Project.verified_repos.count + ProjectRepositoryState.verified_repos.count end def count_verified_wikis - Project.verified_wikis.count + ProjectRepositoryState.verified_wikis.count end def count_verification_failed_repositories - Project.verification_failed_repos.count + ProjectRepositoryState.verification_failed_repos.count end def count_verification_failed_wikis - Project.verification_failed_wikis.count + ProjectRepositoryState.verification_failed_wikis.count end private diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb index ee228827aa6e284284a37b6d3344e506420fcc69..6962918b491a0040c115fde711608a916cadbdcd 100644 --- a/ee/app/models/ee/project.rb +++ b/ee/app/models/ee/project.rb @@ -86,10 +86,8 @@ module Project .where("import_state.retry_count <= ?", ::Gitlab::Mirror::MAX_RETRY) end - scope :with_wiki_enabled, -> { with_feature_enabled(:wiki) } + scope :with_wiki_enabled, -> { with_feature_enabled(:wiki) } - scope :verified_repos, -> { joins(:repository_state).merge(ProjectRepositoryState.verified_repos) } - scope :verified_wikis, -> { joins(:repository_state).merge(ProjectRepositoryState.verified_wikis) } scope :verification_failed_repos, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_repos) } scope :verification_failed_wikis, -> { joins(:repository_state).merge(ProjectRepositoryState.verification_failed_wikis) } scope :for_plan_name, -> (name) { joins(namespace: :plan).where(plans: { name: name }) } diff --git a/ee/changelogs/unreleased/mk-optimize-repo-verification-counts.yml b/ee/changelogs/unreleased/mk-optimize-repo-verification-counts.yml new file mode 100644 index 0000000000000000000000000000000000000000..960938e22ff0f4f4843fa239d6c2e0e1b043c6c4 --- /dev/null +++ b/ee/changelogs/unreleased/mk-optimize-repo-verification-counts.yml @@ -0,0 +1,5 @@ +--- +title: 'Geo: Optimize repository and wiki verification counts' +merge_request: 9939 +author: +type: performance diff --git a/ee/spec/finders/geo/repository_verification_finder_spec.rb b/ee/spec/finders/geo/repository_verification_finder_spec.rb index 1bc6be325b99f01ad4f80dfd55ea66803f56b4ba..5626768dcbcf719884d8eee1557e45bd7b52ec50 100644 --- a/ee/spec/finders/geo/repository_verification_finder_spec.rb +++ b/ee/spec/finders/geo/repository_verification_finder_spec.rb @@ -252,4 +252,56 @@ describe '#find_reverifiable_wikis' do it_behaves_like 'find reverifiable projects', :wiki end + + describe '#count_verified_repositories' do + context 'when a repository is verified' do + it 'includes the repository' do + create(:repository_state, :repository_verified) + + expect(subject.count_verified_repositories).to eq(1) + end + end + + context 'when a repository failed verification' do + it 'excludes the repository' do + create(:repository_state, :repository_failed) + + expect(subject.count_verified_repositories).to eq(0) + end + end + + context 'when a repository has outdated verification' do + it 'excludes the repository' do + create(:repository_state, :repository_outdated) + + expect(subject.count_verified_repositories).to eq(0) + end + end + end + + describe '#count_verified_wikis' do + context 'when a wiki is verified' do + it 'includes the wiki' do + create(:repository_state, :wiki_verified) + + expect(subject.count_verified_wikis).to eq(1) + end + end + + context 'when a wiki failed verification' do + it 'excludes the wiki' do + create(:repository_state, :wiki_failed) + + expect(subject.count_verified_wikis).to eq(0) + end + end + + context 'when a wiki has outdated verification' do + it 'excludes the wiki' do + create(:repository_state, :wiki_outdated) + + expect(subject.count_verified_wikis).to eq(0) + end + end + end end