mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Memoize schools in SurveyItemValues and academic_years in AcademicYear
for performace improvement
This commit is contained in:
parent
c15cb7b483
commit
b250ebe415
3 changed files with 11 additions and 3 deletions
|
|
@ -23,8 +23,14 @@ class AcademicYear < ActiveRecord::Base
|
|||
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
|
||||
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
|
||||
|
||||
private_class_method :academic_years
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class SurveyItemValues
|
|||
end
|
||||
|
||||
def schools
|
||||
School.all.map { |school| [school.dese_id, school] }.to_h
|
||||
@schools ||= School.all.map { |school| [school.dese_id, school] }.to_h
|
||||
end
|
||||
|
||||
def grade
|
||||
|
|
@ -65,7 +65,7 @@ class SurveyItemValues
|
|||
raw_grade = (row['grade'] || row['Grade'] || row['What grade are you in?'])
|
||||
return nil if raw_grade.blank?
|
||||
|
||||
raw_grade = raw_grade.to_i
|
||||
raw_grade.to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ describe SurveyResponsesDataLoader do
|
|||
end
|
||||
|
||||
before :each do
|
||||
AcademicYear.reset_academic_years
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue