Merge pull request #10322 from tchak/chore-backfill-stable-id-custom-limit

chore(task): backfill stable_id with custom limit
This commit is contained in:
Paul Chavard 2024-04-15 09:28:21 +00:00 committed by GitHub
commit bde496b739
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -1,18 +1,18 @@
class Migrations::BackfillStableIdJob < ApplicationJob class Migrations::BackfillStableIdJob < ApplicationJob
queue_as :low_priority 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' sql = "UPDATE champs SET stable_id = t.stable_id, stream = 'main'
FROM types_de_champ t FROM types_de_champ t
WHERE champs.type_de_champ_id = t.id WHERE champs.type_de_champ_id = t.id
AND champs.id IN (SELECT id FROM champs WHERE champs.stable_id IS NULL LIMIT ?);" 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) ActiveRecord::Base.connection.execute(query)
if Champ.exists?(stable_id: nil) 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 end
end end

View file

@ -2,10 +2,11 @@
module Maintenance module Maintenance
class BackfillChampsStableIdTask < MaintenanceTasks::Task class BackfillChampsStableIdTask < MaintenanceTasks::Task
attribute :limit, :integer
no_collection no_collection
def process def process
Migrations::BackfillStableIdJob.perform_later(0) Migrations::BackfillStableIdJob.perform_later(0, limit)
end end
end end
end end