From b89f6cf0f13d95eb13b66fee22282e6160760d97 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 14 Dec 2023 10:30:03 +0100 Subject: [PATCH] correctif(user_deletion_service.perf): timeout via .in_batches. Utilise .pluck(:id) --- app/services/expired/users_deletion_service.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/services/expired/users_deletion_service.rb b/app/services/expired/users_deletion_service.rb index 522649386..f8e448422 100644 --- a/app/services/expired/users_deletion_service.rb +++ b/app/services/expired/users_deletion_service.rb @@ -11,17 +11,21 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter private + # in case of perf downside : + # consider using perform_all_later + # consider changing notify_inactive_close_to_deletion method, taking a user_id, and updating inactive_close_to_expiration_notice_sent_at def send_inactive_close_to_expiration_notice(users) - to_notify_only(users).in_batches do |batch| - batch.each do |user| - send_with_delay(UserMailer.notify_inactive_close_to_deletion(user)) - end - batch.update_all(inactive_close_to_expiration_notice_sent_at: Time.zone.now.utc) + user_ids = to_notify_only(users).pluck(:id) + user_ids.each do |user_id| + send_with_delay(UserMailer.notify_inactive_close_to_deletion(User.find(user_id))) end + User.where(id: user_ids).update_all(inactive_close_to_expiration_notice_sent_at: Time.zone.now.utc) end def delete_notified_users(users) - only_notified(users).find_each do |user| + user_ids = only_notified(users).pluck(:id) + user_ids.each do |user_id| + user = User.find(user_id) begin user.delete_and_keep_track_dossiers_also_delete_user(nil, reason: :user_expired) rescue => e