Revert "Data fix up for Conversation/ConversationParticipant"
This reverts commit b6debfc9fb
.
NOTE: this is not a complete revert. It leaves the addition of the
saftey navigation operators in ConversationHelper
Reason for revert: This data migration has a few performance issues that should be addressed:
- (line 27) Don’t use .each on Conversations, use some sort of batching (probably find_each with :id strat)
- (line 28) n+1 loading conversation_participants
- (line 29) n+1 loading users
Change-Id: I2b18c121a9e6b75e1fe605202542899838af7b80
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/312283
Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Migration-Review: Jacob Burroughs <jburroughs@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
parent
315617c28b
commit
b876adcdf3
|
@ -1,30 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
class PopulateMissingConversationAndConversationParticipantRootAccountIds < ActiveRecord::Migration[7.0]
|
||||
tag :postdeploy
|
||||
|
||||
def self.up
|
||||
DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds.delay_if_production(
|
||||
priority: Delayed::LOWER_PRIORITY,
|
||||
n_strand: ["populate_missing_conversation_and_conversation_participant_root_account_ids", Shard.current.database_server.id]
|
||||
).run
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds
|
||||
def self.run
|
||||
populate_conversation_root_account_id
|
||||
populate_conversation_participant_root_account_id
|
||||
end
|
||||
|
||||
def self.populate_conversation_root_account_id
|
||||
Conversation.where(root_account_ids: [nil, ""]).each do |convo|
|
||||
list_of_ids = convo.conversation_participants.map do |cp|
|
||||
cp.user.root_account_ids
|
||||
end
|
||||
convo.root_account_ids = list_of_ids.flatten.uniq.sort
|
||||
convo.save!
|
||||
end
|
||||
end
|
||||
|
||||
def self.populate_conversation_participant_root_account_id
|
||||
ConversationParticipant.where(root_account_ids: [nil, ""]).find_ids_in_batches do |ids|
|
||||
ConversationParticipant.where(id: ids).joins(:conversation).update_all("root_account_ids=conversations.root_account_ids")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,138 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
describe DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds do
|
||||
let(:account) { account_model }
|
||||
|
||||
describe(".run") do
|
||||
before do
|
||||
@user_1 = User.create(root_account_ids: [account.root_account_id])
|
||||
@user_2 = User.create(root_account_ids: [account.root_account_id])
|
||||
|
||||
@course = Course.create
|
||||
end
|
||||
|
||||
describe "Conversation" do
|
||||
it "updates the root_account_ids when nil" do
|
||||
convo = Conversation.initiate(
|
||||
[@user_1, @user_2],
|
||||
false,
|
||||
{
|
||||
subject: "From #{@user_1.id}",
|
||||
context_type: "Course",
|
||||
context_id: @course.id
|
||||
}
|
||||
)
|
||||
convo.add_message(@user_1, "The quick brown fox jumps over the lazy dog")
|
||||
|
||||
convo.root_account_ids = nil
|
||||
convo.save!
|
||||
|
||||
cp = convo.conversation_participants.first
|
||||
cp.root_account_ids = nil
|
||||
cp.save!
|
||||
|
||||
expect do
|
||||
DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds.run
|
||||
end.to change { convo.reload.root_account_ids }.from([]).to([@user_1.root_account_ids, @user_2.root_account_ids].flatten.uniq.sort)
|
||||
end
|
||||
|
||||
it "updates the root_account_ids when \"\"" do
|
||||
convo = Conversation.initiate(
|
||||
[@user_1, @user_2],
|
||||
false,
|
||||
{
|
||||
subject: "From #{@user_1.id}",
|
||||
context_type: "Course",
|
||||
context_id: @course.id
|
||||
}
|
||||
)
|
||||
convo.add_message(@user_1, "The quick brown fox jumps over the lazy dog")
|
||||
|
||||
convo.root_account_ids = ""
|
||||
convo.save!
|
||||
|
||||
cp = convo.conversation_participants.first
|
||||
cp.root_account_ids = ""
|
||||
cp.save!
|
||||
|
||||
expect(cp.root_account_ids).to match([])
|
||||
|
||||
expect do
|
||||
DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds.run
|
||||
end.to change { convo.reload.root_account_ids }.from([]).to([@user_1.root_account_ids, @user_2.root_account_ids].flatten.uniq.sort)
|
||||
end
|
||||
end
|
||||
|
||||
describe "ConversationParticipant" do
|
||||
it "updates the root_account_ids when nil" do
|
||||
convo = Conversation.initiate(
|
||||
[@user_1, @user_2],
|
||||
false,
|
||||
{
|
||||
subject: "From #{@user_1.id}",
|
||||
context_type: "Course",
|
||||
context_id: @course.id
|
||||
}
|
||||
)
|
||||
convo.add_message(@user_1, "The quick brown fox jumps over the lazy dog")
|
||||
|
||||
convo.root_account_ids = nil
|
||||
convo.save!
|
||||
|
||||
cp = convo.conversation_participants.first
|
||||
cp.root_account_ids = nil
|
||||
cp.save!
|
||||
|
||||
expect(cp.root_account_ids).to match([])
|
||||
|
||||
expect do
|
||||
DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds.run
|
||||
end.to change { cp.reload.root_account_ids }.from([]).to([@user_1.root_account_ids, @user_2.root_account_ids].flatten.uniq.sort)
|
||||
end
|
||||
|
||||
it "updates the root_account_ids when \"\"" do
|
||||
convo = Conversation.initiate(
|
||||
[@user_1, @user_2],
|
||||
false,
|
||||
{
|
||||
subject: "From #{@user_1.id}",
|
||||
context_type: "Course",
|
||||
context_id: @course.id
|
||||
}
|
||||
)
|
||||
convo.add_message(@user_1, "The quick brown fox jumps over the lazy dog")
|
||||
|
||||
convo.root_account_ids = ""
|
||||
convo.save!
|
||||
|
||||
cp = convo.conversation_participants.first
|
||||
cp.root_account_ids = ""
|
||||
cp.save!
|
||||
|
||||
expect(cp.root_account_ids).to match([])
|
||||
|
||||
expect do
|
||||
DataFixup::PopulateMissingConversationAndConversationParticipantRootAccountIds.run
|
||||
end.to change { cp.reload.root_account_ids }.from([]).to([@user_1.root_account_ids, @user_2.root_account_ids].flatten.uniq.sort)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue