From b35b70580d35ae5419d2c89fe1bcd69069704de7 Mon Sep 17 00:00:00 2001 From: Simon Williams Date: Tue, 23 Apr 2013 20:54:10 -0600 Subject: [PATCH] fix performance regression in gradebook csv fixes CNVS-5492 test plan (external): - download the gradebook csv with and without sis ids - it should still work test plan (internal): - run gradebook csv with sis ids from the console and watch the db queries - it should not load quiz submissions - it should not load the account once per student Change-Id: I2665041d8733856d8b32547b49d5af5b69292076 Reviewed-on: https://gerrit.instructure.com/20007 Tested-by: Jenkins Reviewed-by: Cameron Matheson Reviewed-by: Stanley Stuart QA-Review: Amber Taniuchi Product-Review: Simon Williams --- app/models/course.rb | 6 +++++- lib/grade_calculator.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index 78c9e51349a..47c804d5ec1 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1376,8 +1376,12 @@ class Course < ActiveRecord::Base end def gradebook_to_csv(options = {}) + # user: used for name in csv output + # course_section: used for display_name in csv output + # user > pseudonyms: used for sis_user_id/unique_id if options[:include_sis_id] + # user > pseudonyms > account: used in find_pseudonym_for_account > works_for_account includes = [:user, :course_section] - includes = {:user => :pseudonyms, :course_section => []} if options[:include_sis_id] + includes = {:user => {:pseudonyms => :account}, :course_section => []} if options[:include_sis_id] scope = options[:user] ? self.enrollments_visible_to(options[:user]) : self.student_enrollments student_enrollments = scope.includes(includes).order_by_sortable_name # remove duplicate enrollments for students enrolled in multiple sections student_enrollments = student_enrollments.all.uniq_by(&:user_id) diff --git a/lib/grade_calculator.rb b/lib/grade_calculator.rb index 08bf406d023..3816d6f3eae 100644 --- a/lib/grade_calculator.rb +++ b/lib/grade_calculator.rb @@ -44,7 +44,7 @@ class GradeCalculator # recomputes the scores and saves them to each user's Enrollment def compute_scores - @submissions = @course.submissions.for_user(@user_ids) + @submissions = @course.submissions.except(:includes).for_user(@user_ids) submissions_by_user = @submissions.group_by(&:user_id) @user_ids.map do |user_id| user_submissions = submissions_by_user[user_id] || []