Commit a26e25ea authored by Kamil Trzcinski's avatar Kamil Trzcinski

Optimise StuckCiJobsWorker

parent 03b891c5
...@@ -45,9 +45,13 @@ class StuckCiJobsWorker ...@@ -45,9 +45,13 @@ class StuckCiJobsWorker
end end
def search(status, timeout) def search(status, timeout)
builds = Ci::Build.where(status: status).where('ci_builds.updated_at < ?', timeout.ago) Ci::Build.where(status: status).in_batches(of: 1000) do |batch|
builds.joins(:project).merge(Project.without_deleted).includes(:tags, :runner, project: :namespace).find_each(batch_size: 50).each do |build| batch = batch.where('ci_builds.updated_at < ?', timeout.ago)
yield(build) .joins(:project).merge(Project.without_deleted)
.includes(:tags, :runner, project: :namespace)
batch.each do |build|
yield(build)
end
end end
end end
...@@ -58,3 +62,4 @@ class StuckCiJobsWorker ...@@ -58,3 +62,4 @@ class StuckCiJobsWorker
end end
end end
end end
---
title: Optimise StuckCiJobsWorker using cheap SQL query outside, and expensive inside
merge_request:
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