Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Eager load records in stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
allenwq committed Nov 6, 2015
1 parent bbfe59a commit d7126da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def training
@students = is_all ? @course.student_courses : curr_user_course.std_courses
@summary[:student_courses] = @students

submissions = @training.submissions.where(std_course_id: @students)
submissions = @training.submissions.where(std_course_id: @students).includes(:std_course, :gradings, :assessment)
submitted = submissions.map { |sbm| sbm.std_course }

@not_started = @students - submitted
Expand Down
4 changes: 2 additions & 2 deletions app/views/stats/training.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<div id="ruler">&nbsp;</div>
<h3>Question stats</h3>
<% @training.questions.each_with_index do |qn, i| %>
<% @training.questions.includes(:as_question).each_with_index do |qn, i| %>
<section id="question_<%= i + 1%>" style="padding-top: 40px">
<div class="grey_background" style="margin: 10px">
<strong><%= i + 1 %>. </strong>
Expand Down Expand Up @@ -107,7 +107,7 @@
<% end %>
</table>
<% else %>
<% answers = qn.answers_of_students(@students).order(:std_course_id) %>
<% answers = qn.answers_of_students(@students).order(:std_course_id).includes(:std_course) %>
<div style="margin: 10px; margin-left: 50px;">
Wrong / Total Attempts: <strong style="color: red"> <%= answers.where(correct:false).length %> </strong> / <%= answers.length %>
<a class="btn" data-toggle="collapse" href="#code<%= i + 1%>">Click To Expand / Collapse Code</a>
Expand Down

0 comments on commit d7126da

Please sign in to comment.