mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: Introduce bulk channel tracking publisher (#20838)
This commit introduces a Chat::Publisher and MessageBus endpoint that allows for updating a user's channel tracking state in bulk for multiple channels, rather than having to do it for one channel at a time. This also required an improvement to ChannelUnreadsQuery -- now multiple channel IDs can be passed to this to get the unread counts and mention counts for those channels for a user, also increasing efficiency rather than having to do a query for every individual channel. Followup to #20802
This commit is contained in:
@ -129,11 +129,30 @@ RSpec.describe Chat::MarkAllUserChannelsRead do
|
||||
}.by(-2)
|
||||
end
|
||||
|
||||
it "publishes tracking state for all affected channels" do
|
||||
messages = MessageBus.track_publish { result }
|
||||
expect(
|
||||
messages.select { |m| m.channel == "/chat/user-tracking-state/#{current_user.id}" }.count,
|
||||
).to eq(3)
|
||||
it "publishes tracking state in bulk for affected channels" do
|
||||
message =
|
||||
messages.find { |m| m.channel == "/chat/bulk-user-tracking-state/#{current_user.id}" }
|
||||
|
||||
expect(message.data).to eq(
|
||||
channel_1.id.to_s => {
|
||||
"last_read_message_id" => message_2.id,
|
||||
"membership_id" => membership_1.id,
|
||||
"mention_count" => 0,
|
||||
"unread_count" => 0,
|
||||
},
|
||||
channel_2.id.to_s => {
|
||||
"last_read_message_id" => message_4.id,
|
||||
"membership_id" => membership_2.id,
|
||||
"mention_count" => 0,
|
||||
"unread_count" => 0,
|
||||
},
|
||||
channel_3.id.to_s => {
|
||||
"last_read_message_id" => message_6.id,
|
||||
"membership_id" => membership_3.id,
|
||||
"mention_count" => 0,
|
||||
"unread_count" => 0,
|
||||
},
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user