diff --git a/app/jobs/migrations/backfill_stable_id_job.rb b/app/jobs/migrations/backfill_stable_id_job.rb index e145d621c..aa23352ff 100644 --- a/app/jobs/migrations/backfill_stable_id_job.rb +++ b/app/jobs/migrations/backfill_stable_id_job.rb @@ -1,18 +1,18 @@ class Migrations::BackfillStableIdJob < ApplicationJob queue_as :low_priority - BATCH = 100_000 + DEFAULT_LIMIT = 50_000 - def perform(iteration) + def perform(iteration, limit = DEFAULT_LIMIT) sql = "UPDATE champs SET stable_id = t.stable_id, stream = 'main' FROM types_de_champ t WHERE champs.type_de_champ_id = t.id AND champs.id IN (SELECT id FROM champs WHERE champs.stable_id IS NULL LIMIT ?);" - query = ActiveRecord::Base.sanitize_sql_array([sql, BATCH]) + query = ActiveRecord::Base.sanitize_sql_array([sql, limit]) ActiveRecord::Base.connection.execute(query) if Champ.exists?(stable_id: nil) - Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1) + Migrations::BackfillStableIdJob.set(wait: 2.seconds).perform_later(iteration + 1, limit) end end end diff --git a/app/tasks/maintenance/backfill_champs_stable_id_task.rb b/app/tasks/maintenance/backfill_champs_stable_id_task.rb index 040d78d04..070d15c76 100644 --- a/app/tasks/maintenance/backfill_champs_stable_id_task.rb +++ b/app/tasks/maintenance/backfill_champs_stable_id_task.rb @@ -2,10 +2,11 @@ module Maintenance class BackfillChampsStableIdTask < MaintenanceTasks::Task + attribute :limit, :integer no_collection def process - Migrations::BackfillStableIdJob.perform_later(0) + Migrations::BackfillStableIdJob.perform_later(0, limit) end end end