Skip to content

Commit

Permalink
add index specifically supporting Submission.needs_grading
Browse files Browse the repository at this point in the history
Change-Id: I9718a6f931f586b43c45f5505d0c6877eb3605ac
Reviewed-on: https://gerrit.instructure.com/124526
Reviewed-by: Tyler Pickett <[email protected]>
Tested-by: Jenkins
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer authored and roor0 committed Aug 31, 2017
1 parent 866b113 commit 90a0167
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,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
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20170830204122_add_submissions_needs_grading_index.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 90a0167

Please sign in to comment.