Rewrite the query to retrieve job artifacts using CTE

parent 4ca9eb22
......@@ -29,7 +29,20 @@ module Geo
def job_artifacts
Geo::Fdw::Ci::JobArtifact.all unless selective_sync?
Geo::Fdw::Ci::JobArtifact.project_id_in(projects)
query = Geo::Fdw::Ci::JobArtifact.project_id_in(projects).select(:id)
cte = Gitlab::SQL::CTE.new(:restricted_job_artifacts, query)
fdw_job_artifact_table = Geo::Fdw::Ci::JobArtifact.arel_table
inner_join_restricted_job_artifacts =
cte.table
.join(fdw_job_artifact_table, Arel::Nodes::InnerJoin)
.on(cte.table[:id].eq(fdw_job_artifact_table[:id]))
.join_sources
Geo::Fdw::Ci::JobArtifact
.with(cte.to_arel)
.from(cte.table)
.joins(inner_join_restricted_job_artifacts)
end
def lfs_objects
......
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