Skip to content

Commit

Permalink
Refactor Exercise#feedback submission queries
Browse files Browse the repository at this point in the history
We still have a N+1 query here, but could optimize the code workflow nonetheless.
  • Loading branch information
MrSerth committed Nov 6, 2024
1 parent 679de7b commit 0d64a46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 0 additions & 3 deletions app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def feedback
.user_exercise_feedbacks
.includes(:exercise, user: [:programming_groups])
.paginate(page: params[:page], per_page: per_page_param)
@submissions = @feedbacks.map do |feedback|
feedback.exercise.final_submission(feedback.user.programming_groups.find_by(exercise: @exercise).presence || feedback.user)
end
end

def export_external_check
Expand Down
7 changes: 4 additions & 3 deletions app/views/exercises/feedback.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ h1 = link_to_if(policy(@exercise).show?, @exercise, exercise_path(@exercise))
ul.list-unstyled
- comment_presets = UserExerciseFeedbacksController.new.comment_presets
- time_presets = UserExerciseFeedbacksController.new.time_presets
- @feedbacks.each_with_index do |feedback, index|
- @feedbacks.each do |feedback|
- contributor = feedback.user.programming_groups.find_by(exercise: @exercise).presence || feedback.user
li.card.mt-2
.card-header#heading role='tab'
.clearfix.feedback-header
Expand All @@ -31,7 +32,7 @@ h1 = link_to_if(policy(@exercise).show?, @exercise, exercise_path(@exercise))
- if policy(@exercise).detailed_statistics?
.card-footer
.clearfix.feedback-header
span.points.flex-grow-1 = "#{t('exercises.statistics.score')}: #{@submissions[index].score}"
span.working_time.float-end = "#{t('exercises.statistics.worktime')}: #{@exercise.average_working_time_for(feedback.user) || 0}"
span.points.flex-grow-1 = "#{t('exercises.statistics.score')}: #{@exercise.maximum_score(contributor)}"
span.working_time.float-end = "#{t('exercises.statistics.worktime')}: #{@exercise.average_working_time_for(contributor) || 0}"

= render('shared/pagination', collection: @feedbacks)

0 comments on commit 0d64a46

Please sign in to comment.