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:
parent
441b6c148d
commit
6e0db65576
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue