mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Allow chat mentions to have several notifications (#24874)
This PR is a reworked version of https://github.com/discourse/discourse/pull/24670.
In chat, we need the ability to have several notifications per `chat_mention`.
Currently, we have one_to_one relationship between `chat_mentions` and `notifications`:
d7a09fb08d/plugins/chat/app/models/chat/mention.rb (L9)
We want to have one_to_many relationship. This PR implements that by introducing
a join table between `chat_mentions` and `notifications`.
The main motivation for this is that we want to solve some performance problems
with mentions that we're having now. Let's say a user sends a message with @ all
in a channel with 50 members, we do two things in this case at the moment:
- create 50 chat_mentions
- create 50 notifications
We don't want to change how notifications work in core, but we want to be more
efficient in chat, and create only 1 `chat_mention` which would link to 50 notifications.
Also note, that on the side of notifications, having a lot of notifications is not so
big problem, because notifications processing can be queued.
Apart from improving performance, this change will make the code design better.
Note that I've marked the old `chat_mention.notification_id` column as ignored, but
I'm not deleting it in this PR. We'll delete it later in https://github.com/discourse/discourse/pull/24800.
This commit is contained in:

committed by
GitHub

parent
558c709fef
commit
fbd24fa6ae
@ -449,8 +449,8 @@ describe Chat::Message do
|
||||
|
||||
it "destroys chat_mention" do
|
||||
message_1 = Fabricate(:chat_message)
|
||||
notification = Fabricate(:notification)
|
||||
mention_1 = Fabricate(:chat_mention, chat_message: message_1, notification: notification)
|
||||
notification = Fabricate(:notification, notification_type: Notification.types[:chat_mention])
|
||||
mention_1 = Fabricate(:chat_mention, chat_message: message_1, notifications: [notification])
|
||||
|
||||
message_1.reload.destroy!
|
||||
|
||||
|
Reference in New Issue
Block a user