From 53ba442235d6d5c6d1b7c8e7fa899960064b697c Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Tue, 9 Mar 2021 15:41:46 +0100 Subject: [PATCH] fix after party task --- ...144755_backfill_claimant_type_on_avis_table.rake | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake index 9d1b0dcbf..9b9790853 100644 --- a/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake +++ b/lib/tasks/deployment/20210307144755_backfill_claimant_type_on_avis_table.rake @@ -3,13 +3,20 @@ namespace :after_party do task backfill_claimant_type_on_avis_table: :environment do puts "Running deploy task 'backfill_claimant_type_on_avis_table'" + BATCH_SIZE = 20000 + with_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where.not(claimant: { assign_tos: { id: nil } }) - with_dossiers.update_all(claimant_type: 'Instructeur') + + ((with_dossiers.count / BATCH_SIZE).ceil + 1).times do + with_dossiers + .limit(BATCH_SIZE) + .update_all(claimant_type: 'Instructeur') + end without_dossiers = Avis.where(claimant_type: nil).includes(claimant: :assign_to).where(claimant: { assign_tos: { id: nil } }) without_dossiers.find_each do |avis| - claimant = Instructeur.find(avis.claimant_id).user - instructeur = Instructeur.find(avis.instructeur) if avis.instructeur + claimant = avis.claimant.user + instructeur = avis.instructeur if instructeur && avis.experts_procedure_id.blank? User.create_or_promote_to_expert(instructeur.user.email, SecureRandom.hex)