FIX: Handle deleted original message for thread index (#21470)

Since we have channel message retention which deletes
messages, we can end up with cases where the thread
is still around but the message is deleted. We will
handle the cascade delete in a different commit --
for now we will ensure the thread list lookup handles
this case and doesn't error.
This commit is contained in:
Martin Brennan
2023-05-10 13:58:15 +02:00
committed by GitHub
parent cbbaeb55b5
commit 91c5658e9b
5 changed files with 17 additions and 3 deletions

View File

@ -10,7 +10,9 @@ module Chat
def initialize(object, opts)
super(object, opts)
@opts = opts
original_message.thread = object
# Avoids an N1 to re-load the thread in the serializer for original_message.
object.original_message.thread = object
end
def meta

View File

@ -64,7 +64,9 @@ module Chat
)
.where("chat_messages.user_id = ? OR chat_messages.user_id IS NULL", guardian.user.id)
.where(channel_id: channel.id)
.where("original_messages.deleted_at IS NULL AND chat_messages.deleted_at IS NULL")
.where(
"original_messages.deleted_at IS NULL AND chat_messages.deleted_at IS NULL AND original_messages.id IS NOT NULL",
)
.group("chat_threads.id")
.order("last_posted_at DESC NULLS LAST")
.limit(50)