Skip to content

Commit 6b635e2

Browse files
authored
Reduce preloading in school consent jobs (#3310)
This reduces the amount of preloading performed in the school consent request and reminders jobs to try and fix out-of-memory issues we're seeing in production. This has been run once in production and the job has ran successfully.
2 parents d0d8f2e + bd8036e commit 6b635e2

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

app/jobs/school_consent_reminders_job.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@ def perform
77
sessions =
88
Session
99
.send_consent_reminders
10-
.includes(
11-
:programmes,
12-
patient_sessions: {
13-
patient: %i[consents consent_notifications parents]
14-
}
15-
)
16-
.preload(:session_dates)
17-
.eager_load(:location)
10+
.joins(:location)
11+
.includes(:session_dates, :programmes, :patient_sessions, :location)
1812
.merge(Location.school)
1913

20-
sessions.each do |session|
14+
sessions.find_each(batch_size: 1) do |session|
2115
next unless session.open_for_consent?
2216

2317
session.patient_sessions.each do |patient_session|

app/jobs/school_consent_requests_job.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,11 @@ def perform
77
sessions =
88
Session
99
.send_consent_requests
10-
.includes(
11-
:programmes,
12-
patient_sessions: {
13-
patient: [
14-
:consents,
15-
:parents,
16-
{ consent_notifications: :programmes }
17-
]
18-
}
19-
)
20-
.preload(:session_dates)
21-
.eager_load(:location)
10+
.joins(:location)
11+
.includes(:session_dates, :programmes, :patient_sessions, :location)
2212
.merge(Location.school)
2313

24-
sessions.each do |session|
14+
sessions.find_each(batch_size: 1) do |session|
2515
next unless session.open_for_consent?
2616

2717
session.patient_sessions.each do |patient_session|

0 commit comments

Comments
 (0)