add index specifically supporting Submission.needs_grading

Change-Id: I9718a6f931f586b43c45f5505d0c6877eb3605ac
Reviewed-on: https://gerrit.instructure.com/124526
Reviewed-by: Tyler Pickett <tpickett@instructure.com>
Tested-by: Jenkins
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2017-08-30 14:43:11 -06:00
parent 441b6c148d
commit 6e0db65576
2 changed files with 20 additions and 2 deletions

View File

@ -214,8 +214,8 @@ class Submission < ActiveRecord::Base
end
# see #needs_grading?
# When changing these conditions, consider updating index_submissions_on_assignment_id
# to maintain performance.
# When changing these conditions, update index_submissions_needs_grading to
# maintain performance.
def self.needs_grading_conditions
conditions = <<-SQL
submissions.submission_type IS NOT NULL

View File

@ -0,0 +1,18 @@
class AddSubmissionsNeedsGradingIndex < ActiveRecord::Migration[5.0]
tag :postdeploy
disable_ddl_transaction!
def change
# see Submission.needs_grading; duplicated instead of called directly so the migration doesn't
# change even if the query does
add_index :submissions, :assignment_id, name: 'index_submissions_needs_grading', algorithm: :concurrently, where: <<-SQL
submissions.submission_type IS NOT NULL
AND (submissions.excused = 'f' OR submissions.excused IS NULL)
AND (submissions.workflow_state = 'pending_review'
OR (submissions.workflow_state IN ('submitted', 'graded')
AND (submissions.score IS NULL OR NOT submissions.grade_matches_current_submission)
)
)
SQL
end
end