Commit 360fa69f authored by Stan Hu's avatar Stan Hu

Merge branch 'mk/geo/fix-inconsistent-project-registry-queries' into 'master'

Geo: Fix inconsistent project registry queries

Closes #5430

See merge request gitlab-org/gitlab-ee!5171
parents 9ae9d46c 90fb9004
......@@ -12,6 +12,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
validates :project, presence: true, uniqueness: true
scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) }
scope :synced_repos, -> { where(resync_repository: false) }
scope :synced_wikis, -> { where(resync_wiki: false) }
scope :failed_repos, -> { where(arel_table[:repository_retry_count].gt(0)) }
scope :failed_wikis, -> { where(arel_table[:wiki_retry_count].gt(0)) }
scope :verified_repos, -> { where.not(repository_verification_checksum: nil) }
......@@ -42,16 +44,6 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
)
end
def self.synced_repos
where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil)
.where(resync_repository: false)
end
def self.synced_wikis
where.not(last_wiki_synced_at: nil, last_wiki_successful_sync_at: nil)
.where(resync_wiki: false)
end
def repository_sync_due?(scheduled_time)
never_synced_repository? || repository_sync_needed?(scheduled_time)
end
......
---
title: 'Geo: Make synced/failed scopes more consistent'
merge_request: 5171
author:
type: fixed
......@@ -192,7 +192,9 @@ describe Geo::ProjectRegistryFinder, :geo do
end
describe '#count_verified_repositories' do
it 'delegates to #find_verified_repositories' do
it 'delegates to #find_verified_repositories when use_legacy_queries is false' do
expect(subject).to receive(:use_legacy_queries?).and_return(false)
expect(subject).to receive(:find_verified_repositories).and_call_original
subject.count_verified_repositories
......
......@@ -17,6 +17,34 @@ describe Geo::ProjectRegistry do
it { is_expected.to validate_uniqueness_of(:project) }
end
describe '.synced_repos' do
it 'returns clean projects where last attempt to sync succeeded' do
expected = []
expected << create(:geo_project_registry, :synced)
create(:geo_project_registry, :synced, :dirty)
create(:geo_project_registry, :repository_syncing)
expected << create(:geo_project_registry, :wiki_syncing)
expected << create(:geo_project_registry, :wiki_sync_failed)
create(:geo_project_registry, :repository_sync_failed)
expect(described_class.synced_repos).to match_array(expected)
end
end
describe '.synced_wikis' do
it 'returns clean projects where last attempt to sync succeeded' do
expected = []
expected << create(:geo_project_registry, :synced)
create(:geo_project_registry, :synced, :dirty)
expected << create(:geo_project_registry, :repository_syncing)
create(:geo_project_registry, :wiki_syncing)
create(:geo_project_registry, :wiki_sync_failed)
expected << create(:geo_project_registry, :repository_sync_failed)
expect(described_class.synced_wikis).to match_array(expected)
end
end
describe '.failed_repos' do
it 'returns projects where last attempt to sync failed' do
create(:geo_project_registry, :synced)
......
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