fix: I broke the feature where the site would automatically navigate the user to the latest year that had sufficient data when I made response rates calculate on each page load instead of being precalculated and stored in the database. Instead of a database lookup for response rates that meet the sufficiency threshold, I caculate the latest year when a user chooses a school from the welcome page.

mciea-main
rebuilt 2 years ago
parent 5ea01ac916
commit bcfb52c97a

@ -43,12 +43,15 @@ class HomeController < ApplicationController
end
def year
latest_response_rate = ResponseRate.where(school:)
.where('meets_student_threshold = ? or meets_teacher_threshold = ?', true, true)
.joins('inner join academic_years a on response_rates.academic_year_id=a.id')
.order('a.range DESC').first
academic_year = latest_response_rate.academic_year.range if latest_response_rate.present?
return nil unless school.present?
academic_year || AcademicYear.order('range DESC').first.range
academic_year = AcademicYear.all.order(range: :DESC).find do |ay|
Subcategory.all.any? do |subcategory|
rate = subcategory.response_rate(school:, academic_year: ay)
rate.meets_student_threshold || rate.meets_teacher_threshold
end
end
academic_year.range || AcademicYear.order("range DESC").first.range
end
end

Loading…
Cancel
Save