From 366c95af7dc0cc2ad091553683780fada0b34711 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 3 Oct 2024 10:42:47 +0200 Subject: [PATCH] refactor(manager): parallelize sent emails retrieval --- app/controllers/manager/users_controller.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/manager/users_controller.rb b/app/controllers/manager/users_controller.rb index 81e3d0c4b..8d6502579 100644 --- a/app/controllers/manager/users_controller.rb +++ b/app/controllers/manager/users_controller.rb @@ -79,14 +79,17 @@ module Manager email_services = [ Sendinblue::API.new, Dolist::API.new - ] + ].filter(&:properly_configured?) - @sent_mails = email_services - .filter(&:properly_configured?) - .map { |api| api.sent_mails(@user.email) } - .flatten - .sort_by(&:delivered_at) - .reverse + @sent_mails = Concurrent::Array.new + email_services.map do |api| + Thread.new do + mails = api.sent_mails(@user.email) + @sent_mails.concat(mails) + end + end.each(&:join) + + @sent_mails.sort_by!(&:delivered_at).reverse! end def unblock_email