Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions app/lib/patient_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,4 @@ def programme_types_per_session_id_and_year_group
hash[session_id][year_group] << programme_type
end
end

# We preload this association separately because including it in the nested
# `patient_locations` preload (see includes above) caused the updater process
# to be killed, even with very small batches. The likely cause is memory pressure
# from eager loading a deeply nested association graph.
#
# Preloading it here for the distinct `Location` records in each batch keeps
# `StatusGenerator::Programme` query-free without incurring the cost of the
# larger nested preload.
def preload_location_programme_year_groups(batch)
locations = batch.flat_map(&:patient_locations).map(&:location).uniq

ActiveRecord::Associations::Preloader.new(
records: locations,
associations: {
location_programme_year_groups: :location_year_group
}
).call
end
end
Loading