mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 10:41:25 +08:00
FEATURE: Reintroduce better thread reply counter cache (#21197)
This was reverted in 38cebd3ed509524ad635adb107163d0496d0c550. The issue was that I was using Discourse.redis.delete_prefixed which does a slow redis KEYS lookup, which is not advised in production. This commit removes that, and also ensures the periodical thread count update only happens if threading is enabled. I changed to use a redis INCR/DECR for reply count cache. This avoids a round trip to redis to GET the current count, and also avoids multi-process issues, where if there's two processes trying to increment at the same time, they may both receive the same value, add one to it, then both write the same value back. Then, it's only n+1 instead of n+2. This also prevents almost all chat scheduled jobs from running if chat is disabled, the only one remaining is the message retention job.
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
|
||||
@ -233,18 +232,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