DEV: Centralize user updates to a single MessageBus channel. (#17058)

Introduces an interface to publish user updates on the server side and
helps to reduce the growing number of subscriptions on the client side.
This commit is contained in:
Alan Guo Xiang Tan
2022-06-13 14:27:43 +08:00
committed by GitHub
parent bd32656157
commit 94c3bbc2d1
9 changed files with 92 additions and 49 deletions

View File

@ -179,19 +179,19 @@ describe Draft do
it 'updates draft count when a draft is created or destroyed' do
Draft.set(Fabricate(:user), Draft::NEW_TOPIC, 0, "data")
messages = MessageBus.track_publish("/user-drafts/#{user.id}") do
messages = MessageBus.track_publish("/user-updates/#{user.id}") do
Draft.set(user, Draft::NEW_TOPIC, 0, "data")
end
expect(messages.first.data[:draft_count]).to eq(1)
expect(messages.first.data[:has_topic_draft]).to eq(true)
expect(messages.first.data[:payload][:draft_count]).to eq(1)
expect(messages.first.data[:payload][:has_topic_draft]).to eq(true)
messages = MessageBus.track_publish("/user-drafts/#{user.id}") do
messages = MessageBus.track_publish("/user-updates/#{user.id}") do
Draft.where(user: user).destroy_all
end
expect(messages.first.data[:draft_count]).to eq(0)
expect(messages.first.data[:has_topic_draft]).to eq(false)
expect(messages.first.data[:payload][:draft_count]).to eq(0)
expect(messages.first.data[:payload][:has_topic_draft]).to eq(false)
end
describe '#stream' do