Commit 9a6ab07c authored by Michael Kozono's avatar Michael Kozono

Merge branch...

Merge branch '10286-geo-sql-statement-times-out-whilst-determining-job-artifacts-to-sync' into 'master'

Geo - Improve query to determine job artifacts to sync when selective sync is enabled

Closes #10286

See merge request gitlab-org/gitlab!19583
parents b34a6447 b5f37a52
...@@ -13,7 +13,7 @@ module Geo ...@@ -13,7 +13,7 @@ module Geo
belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :job_artifacts belongs_to :project, class_name: 'Geo::Fdw::Project', inverse_of: :job_artifacts
scope :not_expired, -> { where('expire_at IS NULL OR expire_at > ?', Time.current) } scope :not_expired, -> { where('expire_at IS NULL OR expire_at > ?', Time.current) }
scope :project_id_in, ->(ids) { joins(:project).merge(Geo::Fdw::Project.id_in(ids)) } scope :project_id_in, ->(ids) { where(project_id: ids) }
class << self class << self
def inner_join_job_artifact_registry def inner_join_job_artifact_registry
......
...@@ -29,7 +29,20 @@ module Geo ...@@ -29,7 +29,20 @@ module Geo
def job_artifacts def job_artifacts
Geo::Fdw::Ci::JobArtifact.all unless selective_sync? 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 end
def lfs_objects def lfs_objects
......
...@@ -69,7 +69,7 @@ module Geo ...@@ -69,7 +69,7 @@ module Geo
return [] unless job_artifacts_object_store_enabled? return [] unless job_artifacts_object_store_enabled?
job_artifacts_finder.find_migrated_local(batch_size: batch_size, except_artifact_ids: scheduled_file_ids(:job_artifact)) job_artifacts_finder.find_migrated_local(batch_size: batch_size, except_artifact_ids: scheduled_file_ids(:job_artifact))
.pluck(:id) .pluck(Geo::Fdw::Ci::JobArtifact.arel_table[:id])
.map { |id| ['job_artifact', id] } .map { |id| ['job_artifact', id] }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: Geo - Improve query performance to determine job artifacts to sync when selective
sync is enabled
merge_request: 19583
author:
type: performance
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