add conversation improvements
add a comment about root account ids being relative to the birth shard and update some of the references to root_account_ids to use the attribute rather than the helper function fixes VICE-662 flag=none / ---- ---- \ | Test Plan | \ ---- ---- / - specs pass Change-Id: If0397da0350ba74d336ee28de14abfddf69b35bb Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/243998 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: Rob Orton <rob@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
b35813f526
commit
f567028eed
|
@ -75,7 +75,7 @@ class Conversation < ActiveRecord::Base
|
|||
:workflow_state => 'read',
|
||||
:has_attachments => has_attachments?,
|
||||
:has_media_objects => has_media_objects?,
|
||||
:root_account_ids => self.root_account_ids.join(',')
|
||||
:root_account_ids => read_attribute(:root_account_ids)
|
||||
}.merge(options)
|
||||
ConversationParticipant.bulk_insert(user_ids.map{ |user_id|
|
||||
options.merge({:user_id => user_id})
|
||||
|
@ -654,7 +654,7 @@ class Conversation < ActiveRecord::Base
|
|||
def update_root_account_ids
|
||||
if root_account_ids_changed?
|
||||
# ids must be sorted for the scope to work
|
||||
latest_ids = root_account_ids.sort.join(',')
|
||||
latest_ids = read_attribute(:root_account_ids)
|
||||
%w[conversation_participants conversation_messages conversation_message_participants].each do |assoc|
|
||||
scope = self.send(assoc).where("#{assoc}.root_account_ids IS DISTINCT FROM ?", latest_ids).limit(1_000)
|
||||
until scope.update_all(root_account_ids: latest_ids) < 1_000; end
|
||||
|
|
|
@ -21,6 +21,8 @@ module ConversationHelper
|
|||
write_attribute(:root_account_ids, conversation&.root_account_ids&.sort&.join(','))
|
||||
end
|
||||
|
||||
# Note: all ids are relative to the birth shard, if you are going to consume these you should do
|
||||
# `Shard.birth.activate! do`
|
||||
def root_account_ids
|
||||
(read_attribute(:root_account_ids) || '').split(',').map(&:to_i).sort
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue