Merge pull request #10241 from tchak/maintenance-task-optimize
chore(task): optimize maintenance task
This commit is contained in:
commit
f8accdcb8d
1 changed files with 11 additions and 6 deletions
|
@ -2,16 +2,21 @@
|
||||||
|
|
||||||
module Maintenance
|
module Maintenance
|
||||||
class FillChampsStableIdTask < MaintenanceTasks::Task
|
class FillChampsStableIdTask < MaintenanceTasks::Task
|
||||||
|
BATCH = 1_000
|
||||||
|
|
||||||
def collection
|
def collection
|
||||||
Dossier.all
|
(Dossier.last.id / BATCH).ceil.times.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(dossier)
|
def process(batch_number)
|
||||||
dossier.champs
|
dossier_id_start = batch_number * BATCH
|
||||||
.includes(:type_de_champ)
|
dossier_id_end = dossier_id_start + BATCH
|
||||||
.where(stable_id: nil)
|
Champ
|
||||||
|
.where(dossier_id: dossier_id_start..dossier_id_end, stable_id: nil)
|
||||||
|
.joins(:type_de_champ)
|
||||||
|
.select('champs.id, types_de_champ.stable_id as type_de_champ_stable_id')
|
||||||
.find_each do |champ|
|
.find_each do |champ|
|
||||||
champ.update_columns(stable_id: champ.stable_id, stream: 'main')
|
champ.update_columns(stable_id: champ.type_de_champ_stable_id, stream: 'main')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue