Memoize schools in SurveyItemValues and academic_years in AcademicYear

for performace improvement
pull/1/head
rebuilt 3 years ago
parent c15cb7b483
commit b250ebe415

@ -23,8 +23,14 @@ class AcademicYear < ActiveRecord::Base
end end
end end
# This may cause problems if academic years get loaded from csv instead of the current method that requires a code change to the seeder script. This is because a change in code will trigger a complete reload of the application whereas loading from csv does not. This means if we change academic year to load from csv, the set of academic years will be stale when new years are added.
def self.academic_years def self.academic_years
AcademicYear.all.map { |academic_year| [academic_year.range, academic_year] }.to_h @@academic_years ||= AcademicYear.all.map { |academic_year| [academic_year.range, academic_year] }.to_h
end
# Needed to reset the academic years when testing with specs that create the same academic year in a before :each block
def self.reset_academic_years
@@academic_years = nil
end end
private_class_method :academic_years private_class_method :academic_years

@ -57,7 +57,7 @@ class SurveyItemValues
end end
def schools def schools
School.all.map { |school| [school.dese_id, school] }.to_h @schools ||= School.all.map { |school| [school.dese_id, school] }.to_h
end end
def grade def grade
@ -65,7 +65,7 @@ class SurveyItemValues
raw_grade = (row['grade'] || row['Grade'] || row['What grade are you in?']) raw_grade = (row['grade'] || row['Grade'] || row['What grade are you in?'])
return nil if raw_grade.blank? return nil if raw_grade.blank?
raw_grade = raw_grade.to_i raw_grade.to_i
end end
end end

@ -86,6 +86,8 @@ describe SurveyResponsesDataLoader do
end end
before :each do before :each do
AcademicYear.reset_academic_years
setup setup
end end

Loading…
Cancel
Save