Skip to content

Commit

Permalink
Refactor a method so the Assignments#show action is faster
Browse files Browse the repository at this point in the history
In AssignmentsController#show we [email protected]_assignment_group
which was causing this to be called and also causing a:
SELECT "assignment_groups".* 
FROM "assignment_groups" 
WHERE "assignment_groups"."context_id" = 1 
	AND "assignment_groups"."context_type" = 'Course' 
	AND (assignment_groups.workflow_state<>'deleted') 
ORDER BY assignment_groups.position, 
    CAST(LOWER(replace(assignment_groups.name, '\', '\\')) AS bytea)

…even if the assignment already had an assignment_group_id

We should be able to avoid doing that query if we already have an
assignment_group_id

Test plan:
* for an assignment that already has an assignment_grou_id
* go to AssignmentsController#show (with or without a2 on)
* it should not run that ^ query

Change-Id: I64d1d845c50a4cf3e56d2b750954c5a8a778c265
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/218101
Tested-by: Service Cloud Jenkins <[email protected]>
Tested-by: Jenkins
Reviewed-by: Steven Burnett <[email protected]>
QA-Review: Ryan Shaw <[email protected]>
Product-Review: Ryan Shaw <[email protected]>
  • Loading branch information
ryankshaw committed Nov 22, 2019
1 parent 5556288 commit b6d8666
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,11 @@ def default_values
protected :default_values

def ensure_assignment_group(do_save = true)
return if assignment_group_id
self.context.require_assignment_group
assignment_groups = self.context.assignment_groups.active
if !assignment_groups.map(&:id).include?(self.assignment_group_id)
self.assignment_group = assignment_groups.first
Shackles.activate(:master) do
save! if do_save
end
self.assignment_group = self.context.assignment_groups.active.first
if do_save
Shackles.activate(:master) { save! }
end
end

Expand Down

0 comments on commit b6d8666

Please sign in to comment.