iterate accounts politely for assoc updates
Change-Id: Icbb59cfe19ea05cf8e130a7082ed3a0ff823b38f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/245235 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
a93e985654
commit
718457c352
|
@ -1455,7 +1455,9 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.update_all_update_account_associations
|
||||
Account.root_accounts.active.non_shadow.find_each(&:update_account_associations)
|
||||
Account.root_accounts.active.non_shadow.find_in_batches(strategy: :pluck_ids) do |account_batch|
|
||||
account_batch.each(&:update_account_associations)
|
||||
end
|
||||
end
|
||||
|
||||
def course_count
|
||||
|
|
|
@ -1376,15 +1376,25 @@ describe Account do
|
|||
end
|
||||
|
||||
describe "#update_account_associations" do
|
||||
before do
|
||||
@account = Account.default.sub_accounts.create!
|
||||
@c1 = @account.courses.create!
|
||||
@c2 = @account.courses.create!
|
||||
@account.course_account_associations.scope.delete_all
|
||||
end
|
||||
|
||||
it "should update associations for all courses" do
|
||||
account = Account.default.sub_accounts.create!
|
||||
c1 = account.courses.create!
|
||||
c2 = account.courses.create!
|
||||
account.course_account_associations.scope.delete_all
|
||||
expect(account.associated_courses).to eq []
|
||||
account.update_account_associations
|
||||
account.reload
|
||||
expect(account.associated_courses.sort_by(&:id)).to eq [c1, c2]
|
||||
expect(@account.associated_courses).to eq []
|
||||
@account.update_account_associations
|
||||
@account.reload
|
||||
expect(@account.associated_courses.sort_by(&:id)).to eq [@c1, @c2]
|
||||
end
|
||||
|
||||
it "can update associations in batch" do
|
||||
expect(@account.associated_courses).to eq []
|
||||
Account.update_all_update_account_associations
|
||||
@account.reload
|
||||
expect(@account.associated_courses.sort_by(&:id)).to eq [@c1, @c2]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue