From b6b75cee0ef62d81c328d73842e1ed6be082047d Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 12 May 2023 07:52:56 +0200 Subject: [PATCH] Improve SQL query for exercise statistics Removing the call to distinct dramatically improves the page load time. I don't know why, but since we are only using the users to filter the submission, it's not harmful to omit it. --- app/views/exercises/statistics.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercises/statistics.html.slim b/app/views/exercises/statistics.html.slim index 9644f793..a192572f 100644 --- a/app/views/exercises/statistics.html.slim +++ b/app/views/exercises/statistics.html.slim @@ -43,7 +43,7 @@ h1 = @exercise p = @exercise.average_working_time - Hash[:internal_users => t('.internal_users'), :external_users => t('.external_users')].each_pair do |symbol, label| - - submissions = Submission.where(user: @exercise.send(symbol).distinct, exercise: @exercise).in_study_group_of(current_user) + - submissions = Submission.where(user: @exercise.send(symbol), exercise: @exercise).in_study_group_of(current_user) - if !policy(@exercise).detailed_statistics? - submissions = submissions.final - if submissions.any?