Commit 1c4cd06b authored by Brett Walker's avatar Brett Walker Committed by Nick Thomas

Count of verified wikis is incorrect on Geo secondary

parent 53dc5264
......@@ -62,7 +62,7 @@ module Geo
if use_legacy_queries?
legacy_find_verified_wikis
else
find_verified_wikis
fdw_find_verified_wikis
end
relation.count
......@@ -125,10 +125,6 @@ module Geo
Geo::ProjectRegistry.verified_repos
end
def find_verified_wikis
Geo::ProjectRegistry.verified_wikis
end
def find_filtered_failed_project_registries(type = nil)
case type
when 'repository'
......@@ -163,19 +159,7 @@ module Geo
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_enabled_wikis
project_id_matcher =
Geo::Fdw::ProjectFeature.arel_table[:project_id]
.eq(Geo::ProjectRegistry.arel_table[:project_id])
# Only read the IDs of projects with disabled wikis from the remote database
not_exist = Geo::Fdw::ProjectFeature
.where(wiki_access_level: [::ProjectFeature::DISABLED, nil])
.where(project_id_matcher)
.select('1')
.exists
.not
Geo::ProjectRegistry.synced_wikis.where(not_exist)
Geo::ProjectRegistry.synced_wikis.where(fdw_not_disabled_wikis)
end
# @return [ActiveRecord::Relation<Geo::Fdw::Project>]
......@@ -202,6 +186,11 @@ module Geo
).limit(batch_size)
end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_verified_wikis
Geo::ProjectRegistry.verified_wikis.where(fdw_not_disabled_wikis)
end
def fdw_inner_join_repository_state
local_registry_table
.join(fdw_repository_state_table, Arel::Nodes::InnerJoin)
......@@ -209,6 +198,20 @@ module Geo
.join_sources
end
def fdw_not_disabled_wikis
project_id_matcher =
Geo::Fdw::ProjectFeature.arel_table[:project_id]
.eq(Geo::ProjectRegistry.arel_table[:project_id])
# Only read the IDs of projects with disabled wikis from the remote database
Geo::Fdw::ProjectFeature
.where(wiki_access_level: [::ProjectFeature::DISABLED, nil])
.where(project_id_matcher)
.select('1')
.exists
.not
end
#
# Legacy accessors (non FDW)
#
......@@ -264,9 +267,13 @@ module Geo
legacy_find_project_registries(Geo::ProjectRegistry.verified_repos)
end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified projects
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of verified wikis
def legacy_find_verified_wikis
legacy_find_project_registries(Geo::ProjectRegistry.verified_wikis)
legacy_inner_join_registry_ids(
current_node.projects.with_wiki_enabled,
Geo::ProjectRegistry.verified_wikis.pluck(:project_id),
Project
)
end
# @return [ActiveRecord::Relation<Project>] list of synced projects
......
---
title: Fixed incorrect count of verified wikis on a Geo secondary node
merge_request: 5084
author:
type: fixed
......@@ -191,6 +191,69 @@ describe Geo::ProjectRegistryFinder, :geo do
end
end
describe '#count_verified_repositories' do
it 'delegates to #find_verified_repositories' do
expect(subject).to receive(:find_verified_repositories).and_call_original
subject.count_verified_repositories
end
it 'counts projects that verified' do
create(:geo_project_registry, :repository_verified, project: project_repository_verified)
create(:geo_project_registry, :repository_verified, project: build(:project))
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
expect(subject.count_verified_repositories).to eq 2
end
context 'with legacy queries' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end
it 'delegates to #legacy_find_verified_repositories' do
expect(subject).to receive(:legacy_find_verified_repositories).and_call_original
subject.count_verified_repositories
end
it 'counts projects that verified' do
create(:geo_project_registry, :repository_verified, project: project_repository_verified)
create(:geo_project_registry, :repository_verified, project: build(:project))
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
expect(subject.count_verified_repositories).to eq 2
end
end
end
describe '#count_verified_wikis' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end
it 'delegates to #legacy_find_synced_wikis' do
expect(subject).to receive(:legacy_find_verified_wikis).and_call_original
subject.count_verified_wikis
end
it 'counts wikis that verified' do
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: build(:project))
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
expect(subject.count_verified_wikis).to eq 2
end
it 'does not count disabled wikis' do
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled))
expect(subject.count_verified_wikis).to eq 1
end
end
describe '#count_verification_failed_repositories' do
it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('repository').and_call_original
......@@ -424,6 +487,17 @@ describe Geo::ProjectRegistryFinder, :geo do
end
end
describe '#fdw_find_verified_wikis' do
it 'does not count disabled wikis' do
expect(subject).to receive(:fdw_find_verified_wikis).and_call_original
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled))
expect(subject.count_verified_wikis).to eq 1
end
end
describe '#find_unsynced_projects' do
it 'delegates to #fdw_find_unsynced_projects' do
expect(subject).to receive(:fdw_find_unsynced_projects).and_call_original
......
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