Refactor finder to find job artifacts

Remove code duplication in the finders.
parent 018dc130
...@@ -26,7 +26,7 @@ module Geo ...@@ -26,7 +26,7 @@ module Geo
if use_legacy_queries_for_selective_sync? if use_legacy_queries_for_selective_sync?
legacy_finder.syncable legacy_finder.syncable
elsif selective_sync? elsif selective_sync?
job_artifacts.syncable fdw_geo_node.job_artifacts.syncable
else else
Ci::JobArtifact.syncable Ci::JobArtifact.syncable
end end
...@@ -101,19 +101,12 @@ module Geo ...@@ -101,19 +101,12 @@ module Geo
@fdw_geo_node ||= Geo::Fdw::GeoNode.find(current_node.id) @fdw_geo_node ||= Geo::Fdw::GeoNode.find(current_node.id)
end end
def job_artifacts
if selective_sync?
Geo::Fdw::Ci::JobArtifact.project_id_in(fdw_geo_node.projects)
else
Geo::Fdw::Ci::JobArtifact.all
end
end
def registries_for_job_artifacts def registries_for_job_artifacts
if use_legacy_queries_for_selective_sync? if use_legacy_queries_for_selective_sync?
legacy_finder.registries_for_job_artifacts legacy_finder.registries_for_job_artifacts
else else
job_artifacts fdw_geo_node
.job_artifacts
.inner_join_job_artifact_registry .inner_join_job_artifact_registry
.syncable .syncable
end end
...@@ -144,18 +137,19 @@ module Geo ...@@ -144,18 +137,19 @@ module Geo
end end
def fdw_find_unsynced(except_artifact_ids:) def fdw_find_unsynced(except_artifact_ids:)
job_artifacts fdw_geo_node
.missing_job_artifact_registry .job_artifacts
.syncable .syncable
.missing_job_artifact_registry
.id_not_in(except_artifact_ids) .id_not_in(except_artifact_ids)
end end
def fdw_find_migrated_local(except_artifact_ids:) def fdw_find_migrated_local(except_artifact_ids:)
job_artifacts fdw_geo_node
.job_artifacts
.inner_join_job_artifact_registry .inner_join_job_artifact_registry
.with_files_stored_remotely .with_files_stored_remotely
.id_not_in(except_artifact_ids) .id_not_in(except_artifact_ids)
.merge(Geo::JobArtifactRegistry.all)
end end
def legacy_find_unsynced(except_artifact_ids:) def legacy_find_unsynced(except_artifact_ids:)
...@@ -172,7 +166,7 @@ module Geo ...@@ -172,7 +166,7 @@ module Geo
registry_artifact_ids = Geo::JobArtifactRegistry.pluck_artifact_key - except_artifact_ids registry_artifact_ids = Geo::JobArtifactRegistry.pluck_artifact_key - except_artifact_ids
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
legacy_finder.job_artifacts.with_files_stored_remotely, current_node.job_artifacts.with_files_stored_remotely,
registry_artifact_ids, registry_artifact_ids,
Ci::JobArtifact Ci::JobArtifact
) )
......
...@@ -3,15 +3,7 @@ ...@@ -3,15 +3,7 @@
module Geo module Geo
class LegacyJobArtifactRegistryFinder < RegistryFinder class LegacyJobArtifactRegistryFinder < RegistryFinder
def syncable def syncable
job_artifacts.syncable current_node.job_artifacts.syncable
end
def job_artifacts
if selective_sync?
Ci::JobArtifact.project_id_in(current_node.projects)
else
Ci::JobArtifact.all
end
end end
def job_artifacts_synced def job_artifacts_synced
...@@ -43,7 +35,7 @@ module Geo ...@@ -43,7 +35,7 @@ module Geo
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
Geo::JobArtifactRegistry.all, Geo::JobArtifactRegistry.all,
job_artifacts.pluck_primary_key, current_node.job_artifacts.pluck_primary_key,
Geo::JobArtifactRegistry, Geo::JobArtifactRegistry,
foreign_key: :artifact_id foreign_key: :artifact_id
) )
......
...@@ -14,6 +14,12 @@ module Geo ...@@ -14,6 +14,12 @@ module Geo
has_many :geo_node_namespace_links, class_name: 'Geo::Fdw::GeoNodeNamespaceLink' has_many :geo_node_namespace_links, class_name: 'Geo::Fdw::GeoNodeNamespaceLink'
has_many :namespaces, class_name: 'Geo::Fdw::Namespace', through: :geo_node_namespace_links has_many :namespaces, class_name: 'Geo::Fdw::Namespace', through: :geo_node_namespace_links
def job_artifacts
Geo::Fdw::Ci::JobArtifact.all unless selective_sync?
Geo::Fdw::Ci::JobArtifact.project_id_in(projects)
end
def lfs_objects def lfs_objects
return Geo::Fdw::LfsObject.all unless selective_sync? return Geo::Fdw::LfsObject.all unless selective_sync?
......
...@@ -194,6 +194,12 @@ class GeoNode < ApplicationRecord ...@@ -194,6 +194,12 @@ class GeoNode < ApplicationRecord
end end
end end
def job_artifacts
Ci::JobArtifact.all unless selective_sync?
Ci::JobArtifact.project_id_in(projects)
end
def lfs_objects def lfs_objects
return LfsObject.all unless selective_sync? return LfsObject.all unless selective_sync?
......
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