Skip to content

Commit 49a76cf

Browse files
Improve performance
Include vaccination records, and associated programmes in the high level patient query. This means that there no longer needs to be a database request for every patient when loading the Important notices page, because `PatientsHelper.patient_important_notices` can now work on all the patients entirely in memory
1 parent 2636e07 commit 49a76cf

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/controllers/imports/notices_controller.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ class Imports::NoticesController < ApplicationController
66
def index
77
authorize :notices
88

9-
@deceased_patients = policy_scope(Patient).deceased
10-
@invalidated_patients = policy_scope(Patient).invalidated
11-
@restricted_patients = policy_scope(Patient).restricted
9+
@deceased_patients =
10+
policy_scope(Patient).deceased.includes(vaccination_records: :programme)
11+
@invalidated_patients =
12+
policy_scope(Patient).invalidated.includes(
13+
vaccination_records: :programme
14+
)
15+
@restricted_patients =
16+
policy_scope(Patient).restricted.includes(vaccination_records: :programme)
1217
@has_vaccination_records_dont_notify_parents_patients =
13-
policy_scope(Patient).has_vaccination_records_dont_notify_parents
18+
policy_scope(
19+
Patient
20+
).has_vaccination_records_dont_notify_parents.includes(
21+
vaccination_records: :programme
22+
)
1423
end
1524
end

spec/helpers/patients_helper_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@
123123
end
124124

125125
describe "patient_important_notices" do
126-
subject(:notifications) { helper.patient_important_notices(patient) }
126+
subject(:notifications) do
127+
helper.patient_important_notices(patient_with_preloaded_associations)
128+
end
127129

128130
let(:patient) { create(:patient) }
131+
let(:patient_with_preloaded_associations) do
132+
Patient.includes(vaccination_records: :programme).find(patient.id)
133+
end
129134
let(:programme) { create(:programme, :hpv) }
130135

131136
context "when patient has no special status" do

0 commit comments

Comments
 (0)