From 43e0ae0019b130c2e0348e4a32230c2a86a3aef4 Mon Sep 17 00:00:00 2001 From: yoopie Date: Thu, 12 Sep 2024 11:06:25 +0800 Subject: [PATCH] perf(live-feedback-stats): reduce N+1 - sql queries drop from 99 -> ~30 --- app/controllers/course/statistics/assessments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/course/statistics/assessments_controller.rb b/app/controllers/course/statistics/assessments_controller.rb index 7a3b8b5a45..e6db1756f6 100644 --- a/app/controllers/course/statistics/assessments_controller.rb +++ b/app/controllers/course/statistics/assessments_controller.rb @@ -43,7 +43,8 @@ def live_feedback_statistics preload(course: :course_users).first submissions = Course::Assessment::Submission.where(assessment_id: assessment_params[:id]). preload(creator: :course_users) - assessment_live_feedbacks = Course::Assessment::LiveFeedback.where(assessment_id: assessment_params[:id]) + assessment_live_feedbacks = Course::Assessment::LiveFeedback.where(assessment_id: assessment_params[:id]). + preload(:creator, creator: :course_users, code: :comments) @course_users_hash = preload_course_users_hash(@assessment.course)