Refactoring Geo::ProjectRegistryFinder

parent ca2a8ce4
...@@ -7,10 +7,8 @@ module Geo ...@@ -7,10 +7,8 @@ module Geo
end end
def find_unsynced_projects(batch_size:) def find_unsynced_projects(batch_size:)
# Selective project replication adds a wrinkle to FDW queries, so
# we fallback to the legacy version for now.
relation = relation =
if Gitlab::Geo.fdw? && !selective_sync if fdw?
fdw_find_unsynced_projects fdw_find_unsynced_projects
else else
legacy_find_unsynced_projects legacy_find_unsynced_projects
...@@ -20,10 +18,8 @@ module Geo ...@@ -20,10 +18,8 @@ module Geo
end end
def find_projects_updated_recently(batch_size:) def find_projects_updated_recently(batch_size:)
# Selective project replication adds a wrinkle to FDW queries, so
# we fallback to the legacy version for now.
relation = relation =
if Gitlab::Geo.fdw? && !selective_sync if fdw?
fdw_find_projects_updated_recently fdw_find_projects_updated_recently
else else
legacy_find_projects_updated_recently legacy_find_projects_updated_recently
...@@ -34,6 +30,16 @@ module Geo ...@@ -34,6 +30,16 @@ module Geo
protected protected
def fdw?
# Selective project replication adds a wrinkle to FDW
# queries, so we fallback to the legacy version for now.
Gitlab::Geo.fdw? && !selective_sync
end
def fdw_table
Geo::Fdw::Project.table_name
end
def selective_sync def selective_sync
current_node.restricted_project_ids current_node.restricted_project_ids
end end
...@@ -44,16 +50,12 @@ module Geo ...@@ -44,16 +50,12 @@ module Geo
# @return [ActiveRecord::Relation<Geo::Fdw::Project>] # @return [ActiveRecord::Relation<Geo::Fdw::Project>]
def fdw_find_unsynced_projects def fdw_find_unsynced_projects
fdw_table = Geo::Fdw::Project.table_name
Geo::Fdw::Project.joins("LEFT OUTER JOIN project_registry ON project_registry.project_id = #{fdw_table}.id") Geo::Fdw::Project.joins("LEFT OUTER JOIN project_registry ON project_registry.project_id = #{fdw_table}.id")
.where('project_registry.project_id IS NULL') .where('project_registry.project_id IS NULL')
end end
# @return [ActiveRecord::Relation<Geo::Fdw::Project>] # @return [ActiveRecord::Relation<Geo::Fdw::Project>]
def fdw_find_projects_updated_recently def fdw_find_projects_updated_recently
fdw_table = Geo::Fdw::Project.table_name
Geo::Fdw::Project.joins("INNER JOIN project_registry ON project_registry.project_id = #{fdw_table}.id") Geo::Fdw::Project.joins("INNER JOIN project_registry ON project_registry.project_id = #{fdw_table}.id")
.merge(Geo::ProjectRegistry.dirty) .merge(Geo::ProjectRegistry.dirty)
.merge(Geo::ProjectRegistry.retry_due) .merge(Geo::ProjectRegistry.retry_due)
......
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