fix assignments_needing_x sharding issues

course_ids were being looked up on the currently active shard and then used on
the user shard

fixes CNVS-14449

test plan:
- create a teacher and two shards, each with a course
- enroll the teacher in both courses (so they are now a cross-shard user)
- in each course, create a student and have them submit an assignment
- load the dashboard on each shard
- both shards To Do lists should be the same -- they should both list
  2 assignments (one from each shard/course) as needing grading

Change-Id: Id34541f7d7144fa0ffb8b221a95aa9369118f50a
Reviewed-on: https://gerrit.instructure.com/38372
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Simon Williams 2014-07-28 17:03:06 -06:00
parent daf6143e0b
commit 5cebbfacf7
2 changed files with 28 additions and 24 deletions

View File

@ -1364,6 +1364,7 @@ class User < ActiveRecord::Base
end
def assignments_needing_submitting(opts={})
shard.activate do
course_ids = Shackles.activate(:slave) do
if opts[:contexts]
(Array(opts[:contexts]).map(&:id) &
@ -1375,7 +1376,6 @@ class User < ActiveRecord::Base
opts = {limit: 15}.merge(opts.slice(:due_after, :limit))
shard.activate do
Rails.cache.fetch([self, 'assignments_needing_submitting', course_ids, opts].cache_key, expires_in: 15.minutes) do
Shackles.activate(:slave) do
limit = opts[:limit]
@ -1399,6 +1399,7 @@ class User < ActiveRecord::Base
end
def assignments_needing_grading(opts={})
shard.activate do
course_ids = Shackles.activate(:slave) do
if opts[:contexts]
(Array(opts[:contexts]).map(&:id) &
@ -1410,7 +1411,6 @@ class User < ActiveRecord::Base
opts = {limit: 15}.merge(opts.slice(:limit))
shard.activate do
Rails.cache.fetch([self, 'assignments_needing_grading', course_ids, opts].cache_key, expires_in: 15.minutes) do
Shackles.activate(:slave) do
limit = opts[:limit]

View File

@ -2211,9 +2211,13 @@ describe User do
end
it "should find assignments from all shards" do
[Shard.default, @shard1, @shard2].each do |shard|
shard.activate do
@teacher.assignments_needing_grading.sort_by(&:id).should ==
[@course1.assignments.first, @course2.assignments.first, @assignment3].sort_by(&:id)
end
end
end
it "should honor ignores for a separate shard" do
@teacher.ignore_item!(@assignment3, 'grading')