Commit 8dee4cba authored by Douwe Maan's avatar Douwe Maan

Merge branch 'mk/optimize-repo-verification-counts' into 'master'

Geo: Optimize repository and wiki verification counts

Closes #10279

See merge request gitlab-org/gitlab-ee!9939
parents d79d6fa1 f10a1777
......@@ -61,19 +61,19 @@ module Geo
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
......
......@@ -86,10 +86,8 @@ module EE
.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 }) }
......
---
title: 'Geo: Optimize repository and wiki verification counts'
merge_request: 9939
author:
type: performance
......@@ -252,4 +252,56 @@ describe Geo::RepositoryVerificationFinder, :postgresql do
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
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