demarches-normaliennes/app
Pierre de La Morinerie 0e35bc609d notifications: don't preload dossiers on instructeurs
This request currently times out almost every night in production.

It's because although Instructeurs are loaded in batches (default batch
size is 1000), loading all dossiers for 1000 instructeurs is slow.

Turns out the code executed after this query to compute notifications
doesn't even use these dossiers. Indeed it is faster not to preload
them: both the initial query and the total treatment time are shorter.

Here's a quick benchmark made locally (but using production data):

- Before this commit:

	Benchmark.measure { pp Instructeur.includes(assign_to: { procedure: :dossiers }).where(assign_tos: { daily_email_notifications_enabled: true }).limit(100).m
ap(&:email_notification_data) }

Only the initial query : 35s
Total time : 97s

- Without preloading dossiers:

	Benchmark.measure { pp Instructeur.includes(assign_to: :procedure).where(assign_tos: { daily_email_notifications_enabled: true }).limit(100).m
ap(&:email_notification_data) }

Only the initial query : 0.08s (400x faster)
Total time : 29s (3,3x faster)

Plus it doesn't timeout, of course.
2021-12-09 12:10:00 +01:00
..
assets feat (api particulier): add Pole emploi field 2021-12-08 10:36:25 +01:00
controllers small wording fixes 2021-12-08 11:19:30 +01:00
dashboards feat(manager): add procedure_expires_when_termine_enabled to administrate 2021-12-06 07:49:59 +01:00
fields manager: remove support for old pj 2019-07-30 16:11:17 +02:00
graphql fix(graphql): do not crash if attestation is nil 2021-12-08 13:12:42 +01:00
helpers views: prevent procedure publication on validation error 2021-11-30 13:34:41 +01:00
javascript fix(champ): save departement name without code prefix 2021-12-06 20:58:08 +01:00
jobs refactor(mail.delay): use simplier implementation using after_action to prevent email delivery with delay 2021-11-16 15:12:05 +01:00
lib feat(helpscout): add a tag to messages submited through contact form 2021-12-09 11:47:13 +01:00
mailers feat(UserMailer.france_connect_merge_confirmation): in addition to distance_of_time_in_words, add exact expiration date 2021-11-25 17:34:37 +01:00
models fix(graphql): do not crash if attestation is nil 2021-12-08 13:12:42 +01:00
policies policies: clarify the role of ChampPolicy 2020-06-24 15:42:30 +02:00
schemas feat(api particulier): add Pole Emploi adapter 2021-12-08 10:36:11 +01:00
serializers fix(dossier): use depose_at instead of en_construction_at 2021-12-06 15:49:17 +01:00
services notifications: don't preload dossiers on instructeurs 2021-12-09 12:10:00 +01:00
validators models: validate that no drop-downs are empty on publishing 2021-12-02 09:00:37 +01:00
views feat (api particulier): add Pole emploi field 2021-12-08 10:36:25 +01:00