diff --git a/app/controllers/analyze_controller.rb b/app/controllers/analyze_controller.rb index 3fd5b5be..2a6fb055 100644 --- a/app/controllers/analyze_controller.rb +++ b/app/controllers/analyze_controller.rb @@ -6,7 +6,7 @@ class AnalyzeController < SqmApplicationController @subcategory ||= Subcategory.find_by_subcategory_id(params[:subcategory_id]) @subcategory ||= Subcategory.find_by_subcategory_id('1A') - @measure = @subcategory.measures.first + @measure = @subcategory.measures.includes([:admin_data_items]).first @academic_year ||= AcademicYear.order('range DESC').first end end diff --git a/app/controllers/overview_controller.rb b/app/controllers/overview_controller.rb index b05c6413..bedf6094 100644 --- a/app/controllers/overview_controller.rb +++ b/app/controllers/overview_controller.rb @@ -3,7 +3,7 @@ class OverviewController < SqmApplicationController helper VarianceHelper def index - @variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure)) + @variance_chart_row_presenters = measures.map(&method(:presenter_for_measure)) @category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category:) } end @@ -16,8 +16,13 @@ class OverviewController < SqmApplicationController end def check_empty_dataset - @has_empty_dataset = Measure.all.all? do |measure| + @has_empty_dataset = measures.all? do |measure| measure.none_meet_threshold? school: @school, academic_year: @academic_year end end + + def measures + @measures ||= Measure.all.includes(%i[scales admin_data_items subcategory + category]).includes(subcategory: :measures) + end end diff --git a/app/models/measure.rb b/app/models/measure.rb index 5cd0b3e0..e660d579 100644 --- a/app/models/measure.rb +++ b/app/models/measure.rb @@ -1,5 +1,6 @@ class Measure < ActiveRecord::Base belongs_to :subcategory + has_one :category, through: :subcategory has_many :scales has_many :admin_data_items, through: :scales has_many :survey_items, through: :scales @@ -94,13 +95,14 @@ class Measure < ActiveRecord::Base def sufficient_student_data?(school:, academic_year:) return false unless includes_student_survey_items? - subcategory.student_response_rate(school:, academic_year:).meets_student_threshold? + @sufficient_student_data ||= subcategory.student_response_rate(school:, + academic_year:).meets_student_threshold? end def sufficient_teacher_data?(school:, academic_year:) return false unless includes_teacher_survey_items? - subcategory.teacher_response_rate(school:, academic_year:).meets_teacher_threshold? + @sufficient_teacher_data ||= subcategory.teacher_response_rate(school:, academic_year:).meets_teacher_threshold? end def all_admin_data_collected?(school:, academic_year:) diff --git a/app/presenters/variance_chart_row_presenter.rb b/app/presenters/variance_chart_row_presenter.rb index 2c9dfa29..10a3b216 100644 --- a/app/presenters/variance_chart_row_presenter.rb +++ b/app/presenters/variance_chart_row_presenter.rb @@ -10,7 +10,7 @@ class VarianceChartRowPresenter @meets_student_threshold = score.meets_student_threshold? @measure_name = @measure.name @measure_id = @measure.measure_id - @category = @measure.subcategory.category + @category = @measure.category end def sufficient_data? diff --git a/app/views/overview/index.html.erb b/app/views/overview/index.html.erb index 311d260a..6605e26e 100644 --- a/app/views/overview/index.html.erb +++ b/app/views/overview/index.html.erb @@ -63,6 +63,7 @@ +<% cache [@school, @academic_year] do %>

School Quality Framework Indicators

@@ -88,14 +89,15 @@
- <%= render partial: "quality_framework_indicators", locals: { category_presenters: @category_presenters } %> + <%= render partial: "quality_framework_indicators", locals: { category_presenters: @category_presenters }, cached: true %>

Distance From Benchmark

- <%= render partial: "variance_chart", locals: { presenters: @variance_chart_row_presenters } %> + <%= render partial: "variance_chart", locals: { presenters: @variance_chart_row_presenters } , cached: true %>
+<% end %> <% if @district == District.find_by_name("Boston") %> <%= render partial: 'layouts/boston_modal' %>