mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
DEV: Use UploadReference instead of ChatUpload in chat (#19947)
We've had the UploadReference table for some time now in core, but it was added after ChatUpload was and chat was just never moved over to this new system. This commit changes all chat code dealing with uploads to create/ update/delete/query UploadReference records instead of ChatUpload records for consistency. At a later date we will drop the ChatUpload table, but for now keeping it for data backup. The migration + post migration are the same, we need both in case any chat uploads are added/removed during deploy.
This commit is contained in:
@ -83,7 +83,8 @@ class Chat::ChatMessageUpdater
|
||||
def update_uploads(upload_info)
|
||||
return unless upload_info[:changed]
|
||||
|
||||
ChatUpload.where(chat_message: @chat_message).destroy_all
|
||||
DB.exec("DELETE FROM chat_uploads WHERE chat_message_id = #{@chat_message.id}")
|
||||
UploadReference.where(target: @chat_message).destroy_all
|
||||
@chat_message.attach_uploads(upload_info[:uploads])
|
||||
end
|
||||
|
||||
|
@ -147,7 +147,7 @@ class ChatTranscriptService
|
||||
def messages
|
||||
@messages ||=
|
||||
ChatMessage
|
||||
.includes(:user, chat_uploads: :upload)
|
||||
.includes(:user, upload_references: :upload)
|
||||
.where(id: @message_ids, chat_channel_id: @channel.id)
|
||||
.order(:created_at)
|
||||
end
|
||||
|
@ -125,10 +125,10 @@ class Chat::MessageMover
|
||||
SQL
|
||||
|
||||
DB.exec(<<~SQL)
|
||||
UPDATE chat_uploads cu
|
||||
SET chat_message_id = mm.new_chat_message_id
|
||||
UPDATE upload_references uref
|
||||
SET target_id = mm.new_chat_message_id
|
||||
FROM moved_chat_messages mm
|
||||
WHERE cu.chat_message_id = mm.old_chat_message_id
|
||||
WHERE uref.target_id = mm.old_chat_message_id AND uref.target_type = 'ChatMessage'
|
||||
SQL
|
||||
|
||||
DB.exec(<<~SQL)
|
||||
|
Reference in New Issue
Block a user