switch to using effective_due_dates in gradebook_importer

This switches the gradebook import process to using EffectiveDueDates
to find student specific due dates.  This avoids the N+1's that
calling Submission#cache_due_date can create.

closes CNVS-35366

test plan:
 - Smoketest that gradebook importer still works, especially with a
   few assignments overrides
 - Speed test the gradebook on a large course

Change-Id: Ib669fbede2c50e78a53420868492342109df5b13
Reviewed-on: https://gerrit.instructure.com/103937
Tested-by: Jenkins
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Reviewed-by: Derek Bender <djbender@instructure.com>
QA-Review: KC Naegle <knaegle@instructure.com>
Product-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
Keith Garner 2017-03-03 13:18:30 -06:00 committed by Keith T. Garner
parent 76501fe6b9
commit 9f06f54427
2 changed files with 8 additions and 6 deletions

View File

@ -82,8 +82,6 @@ class EffectiveDueDates
find_effective_due_date(student_id, assignment_id).fetch(:grading_period_id, nil)
end
private
def find_effective_due_date(student_id, assignment_id)
find_effective_due_dates_for_assignment(assignment_id).fetch(student_id, {})
end
@ -92,6 +90,8 @@ class EffectiveDueDates
to_hash.fetch(assignment_id, {})
end
private
def usable_student_id?(student_id)
return false unless student_id.present?
return false unless student_id.to_i.present?

View File

@ -75,7 +75,7 @@ class GradebookImporter
# preload a ton of data that presumably we'll be querying
@context.preload_user_roles!
@all_assignments = @context.assignments
.preload({ context: :account }, :assignment_overrides, :assignment_override_students)
.preload({ context: :account })
.published
.gradeable
.select(ASSIGNMENT_PRELOADED_FIELDS)
@ -115,10 +115,11 @@ class GradebookImporter
periods = GradingPeriod.for(@context)
# preload is_admin to avoid N+1
is_admin = @context.account_membership_allows(@user)
# Preload effective due dates to avoid N+1s
effective_due_dates = EffectiveDueDates.for_course(@context, @all_assignments.values)
@original_submissions = @context.submissions
.preload(assignment: [{ context: :account }, :assignment_overrides,
:assignment_override_students])
.preload(assignment: { context: :account })
.select(['submissions.id', :assignment_id, :user_id, :score, :excused, :cached_due_date, 'submissions.updated_at'])
.where(assignment_id: assignment_ids, user_id: user_ids)
.map do |submission|
@ -155,7 +156,8 @@ class GradebookImporter
new_submission = Submission.new
new_submission.user = student
new_submission.assignment = assignment
new_submission.cache_due_date
new_submission.cached_due_date =
effective_due_dates.find_effective_due_date(student.id, assignment.id).fetch(:due_at, nil)
submission['gradeable'] = gradeable?(
submission: new_submission,
periods: periods,