Browse Source

Fix N+1 query in scheme answer options page (#1614)

pull/1518/head
James Rose 2 years ago committed by GitHub
parent
commit
239d46d569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/form/lettings/questions/scheme_id.rb

4
app/models/form/lettings/questions/scheme_id.rb

@ -30,10 +30,10 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question
def displayed_answer_options(lettings_log, _user = nil) def displayed_answer_options(lettings_log, _user = nil)
organisation = lettings_log.owning_organisation || lettings_log.created_by&.organisation organisation = lettings_log.owning_organisation || lettings_log.created_by&.organisation
schemes = if organisation schemes = if organisation
Scheme.select(:id).where(owning_organisation_id: organisation.id, Scheme.includes(:locations).select(:id).where(owning_organisation_id: organisation.id,
confirmed: true) confirmed: true)
else else
Scheme.select(:id).where(confirmed: true) Scheme.includes(:locations).select(:id).where(confirmed: true)
end end
filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL",
Time.zone.today)).map(&:id) Time.zone.today)).map(&:id)

Loading…
Cancel
Save