mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 12:45:24 +08:00
FEATURE: Better thread reply counter cache (#21108)
This commit introduces a redis cache over the top of the thread replies_count DB cache, so that we can quickly and accurately increment/decrement the reply count for all users and not have to constantly update the database-level count. This is done so the UI can have a count that is displayed to the users on each thread indicator, that appears to live update on each chat message create/trash/recover inside the thread. This commit also introduces the `Chat::RestoreMessage` service and moves the restore endpoint into the `Api::ChannelMessages` controller as part of incremental migrations to move things out of ChatController. Finally, this commit refactors `Chat::Publisher` to be less repetitive with its `MessageBus` sending code.
This commit is contained in:
@ -4,4 +4,10 @@ class Chat::Api::ChannelMessagesController < Chat::ApiController
|
||||
def destroy
|
||||
with_service(Chat::TrashMessage) { on_model_not_found(:message) { raise Discourse::NotFound } }
|
||||
end
|
||||
|
||||
def restore
|
||||
with_service(Chat::RestoreMessage) do
|
||||
on_model_not_found(:message) { raise Discourse::NotFound }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,8 +12,7 @@ module Chat
|
||||
# these endpoints require a standalone find because they need to be
|
||||
# able to get deleted channels and recover them.
|
||||
before_action :find_chatable, only: %i[enable_chat disable_chat]
|
||||
before_action :find_chat_message,
|
||||
only: %i[delete restore lookup_message edit_message rebake message_link]
|
||||
before_action :find_chat_message, only: %i[lookup_message edit_message rebake message_link]
|
||||
before_action :set_channel_and_chatable_with_access_check,
|
||||
except: %i[
|
||||
respond
|
||||
@ -225,18 +224,6 @@ module Chat
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
def restore
|
||||
chat_channel = @message.chat_channel
|
||||
guardian.ensure_can_restore_chat!(@message, chat_channel.chatable)
|
||||
updated = @message.recover!
|
||||
if updated
|
||||
Chat::Publisher.publish_restore!(chat_channel, @message)
|
||||
render json: success_json
|
||||
else
|
||||
render_json_error(@message)
|
||||
end
|
||||
end
|
||||
|
||||
def rebake
|
||||
guardian.ensure_can_rebake_chat_message!(@message)
|
||||
@message.rebake!(invalidate_oneboxes: true)
|
||||
|
Reference in New Issue
Block a user