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:
Martin Brennan
2023-03-28 09:36:28 +10:00
committed by GitHub
parent 326a7a47e7
commit cab4b2cfba
6 changed files with 184 additions and 64 deletions

View File

@ -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