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.
This commit is contained in:
Sebastian Serth
2023-05-12 07:52:56 +02:00
parent e93a6ea1f6
commit b6b75cee0e

View File

@ -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?