perf: reduce number of queries for respondents

This commit is contained in:
Nelson Jovel 2023-12-26 16:23:29 -08:00
parent 54ea72898d
commit 8fb0a280ca
6 changed files with 24 additions and 16 deletions

View file

@ -21,6 +21,6 @@ class School < ApplicationRecord
end
def grades(academic_year:)
@grades ||= Respondent.find_by(school: self, academic_year:)&.enrollment_by_grade&.keys || (-1..12).to_a
@grades ||= Respondent.by_school_and_year(school: self, academic_year:)&.enrollment_by_grade&.keys || (-1..12).to_a
end
end