Merge pull request #9854 from mfo/US/fix-user-deletion-service-in-batches

Tech, correctif sur le service d'expiration des usagers inactif qui timeoutait via `.in_batches`. Utilise `.pluck(:id)`
This commit is contained in:
mfo 2023-12-14 13:27:30 +00:00 committed by GitHub
commit 186f85f81a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,17 +11,21 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
private 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) def send_inactive_close_to_expiration_notice(users)
to_notify_only(users).in_batches do |batch| user_ids = to_notify_only(users).pluck(:id)
batch.each do |user| user_ids.each do |user_id|
send_with_delay(UserMailer.notify_inactive_close_to_deletion(user)) send_with_delay(UserMailer.notify_inactive_close_to_deletion(User.find(user_id)))
end
batch.update_all(inactive_close_to_expiration_notice_sent_at: Time.zone.now.utc)
end end
User.where(id: user_ids).update_all(inactive_close_to_expiration_notice_sent_at: Time.zone.now.utc)
end end
def delete_notified_users(users) 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 begin
user.delete_and_keep_track_dossiers_also_delete_user(nil, reason: :user_expired) user.delete_and_keep_track_dossiers_also_delete_user(nil, reason: :user_expired)
rescue => e rescue => e