spec: improve performances of notification_mailer_preview

The time to find the last dossier could be very long for large
procedures.
This commit is contained in:
Pierre de La Morinerie 2022-05-10 15:58:27 +02:00
parent 36f5a98b26
commit e8b6731af8

View file

@ -26,8 +26,7 @@ class NotificationMailerPreview < ActionMailer::Preview
end
def dossier_with_image
procedure = Procedure.where(id: Mails::InitiatedMail.where("body like ?", "%<img%").pluck(:procedure_id).uniq).order("RANDOM()").first
procedure.dossiers.last
Dossier.joins(procedure: [:initiated_mail]).where("initiated_mails.body like ?", "%<img%").order('RANDOM()').first
end
def dossier_with_motivation