Commit 364a2d1c authored by Stan Hu's avatar Stan Hu

Merge branch '37324-fix-statement-timeout-while-finding-projects-to-reverify' into 'master'

Geo - Optimize the query to return reverifiable projects on Geo primary node

See merge request gitlab-org/gitlab!38732
parents c3384edc 45da22ff
......@@ -126,15 +126,21 @@ module Geo
repository_state_table["last_#{type}_verification_ran_at"].eq(nil).or(
repository_state_table["last_#{type}_verification_ran_at"].lteq(interval))
# We should prioritize less active projects first because high active
# projects have their repositories verified more frequently.
query =
Project.joins(:repository_state)
projects_table
.join(repository_state_table).on(project_id_matcher)
.project(projects_table[:id], projects_table[:last_repository_updated_at])
.where(verification_succeded.and(verified_before_interval))
.order(last_repository_updated_at_asc)
.limit(batch_size)
.take(batch_size)
apply_shard_restriction(query)
query = apply_shard_restriction(query)
cte = Gitlab::SQL::CTE.new(:reverifiable_projects, query)
# We should prioritize less active projects first because high active
# projects have their repositories verified more frequently.
Project.with(cte.to_arel)
.from(cte.alias_to(projects_table))
.order(last_repository_updated_at_asc)
end
# rubocop: enable CodeReuse/ActiveRecord
......
---
title: Geo - Optimize the query to return reverifiable projects on Geo primary node
merge_request: 38732
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