mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
fix: reduce number of n+1 queries
This commit is contained in:
parent
2a125aa058
commit
d2efec1574
2 changed files with 9 additions and 4 deletions
|
|
@ -6,11 +6,11 @@ class OverviewController < SqmApplicationController
|
|||
|
||||
def index
|
||||
@variance_chart_row_presenters = measures.map(&method(:presenter_for_measure))
|
||||
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category:) }
|
||||
@category_presenters = categories.map { |category| CategoryPresenter.new(category:) }
|
||||
@student_response_rate_presenter = ResponseRatePresenter.new(focus: :student, school: @school,
|
||||
academic_year: @academic_year)
|
||||
academic_year: @academic_year)
|
||||
@teacher_response_rate_presenter = ResponseRatePresenter.new(focus: :teacher, school: @school,
|
||||
academic_year: @academic_year)
|
||||
academic_year: @academic_year)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -33,6 +33,10 @@ class OverviewController < SqmApplicationController
|
|||
end
|
||||
|
||||
def subcategories
|
||||
@subcategories ||= Subcategory.all.includes(%i[measures admin_data_items category])
|
||||
@subcategories ||= categories.flat_map(&:subcategories)
|
||||
end
|
||||
|
||||
def categories
|
||||
@categories ||= Category.sorted.includes(%i[measures admin_data_items subcategories])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ class Category < ActiveRecord::Base
|
|||
|
||||
has_many :subcategories
|
||||
has_many :measures, through: :subcategories
|
||||
has_many :admin_data_items, through: :measures
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue