mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 16:22:20 +08:00
PERF: Move user-tips and narrative to per-user messagebus channels (#19773)
Using a shared channel with per-message permissions means that every client is updated with the channel's 'last_id', even if there are no messages available to them. Per-user channel names avoid this problem - the last_id will only be incremented when there is a message for the given user.
This commit is contained in:
@ -13,11 +13,19 @@ export default {
|
|||||||
this.messageBus = container.lookup("service:message-bus");
|
this.messageBus = container.lookup("service:message-bus");
|
||||||
this.site = container.lookup("service:site");
|
this.site = container.lookup("service:site");
|
||||||
|
|
||||||
this.messageBus.subscribe("/user-tips", this.onMessage);
|
this.messageBus.subscribe(
|
||||||
|
`/user-tips/${this.currentUser.id}`,
|
||||||
|
this.onMessage
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
this.messageBus?.unsubscribe("/user-tips", this.onMessage);
|
if (this.currentUser) {
|
||||||
|
this.messageBus?.unsubscribe(
|
||||||
|
`/user-tips/${this.currentUser.id}`,
|
||||||
|
this.onMessage
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
|
@ -251,7 +251,11 @@ class UserUpdater
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if attributes.key?(:seen_popups) || attributes.key?(:skip_new_user_tips)
|
if attributes.key?(:seen_popups) || attributes.key?(:skip_new_user_tips)
|
||||||
MessageBus.publish("/user-tips", user.user_option.seen_popups, user_ids: [user.id])
|
MessageBus.publish(
|
||||||
|
"/user-tips/#{user.id}",
|
||||||
|
user.user_option.seen_popups,
|
||||||
|
user_ids: [user.id],
|
||||||
|
)
|
||||||
end
|
end
|
||||||
DiscourseEvent.trigger(:user_updated, user)
|
DiscourseEvent.trigger(:user_updated, user)
|
||||||
end
|
end
|
||||||
|
@ -15,9 +15,9 @@ export default {
|
|||||||
this.appEvents = container.lookup("service:app-events");
|
this.appEvents = container.lookup("service:app-events");
|
||||||
|
|
||||||
withPluginApi("0.8.7", (api) => {
|
withPluginApi("0.8.7", (api) => {
|
||||||
const currentUser = api.getCurrentUser();
|
this.currentUser = api.getCurrentUser();
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!this.currentUser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,17 +41,19 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.messageBus.subscribe(
|
this.messageBus.subscribe(
|
||||||
"/new_user_narrative/tutorial_search",
|
`/new_user_narrative/tutorial_search/${this.currentUser.id}`,
|
||||||
this.onMessage
|
this.onMessage
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
this.messageBus?.unsubscribe(
|
if (this.currentUser) {
|
||||||
"/new_user_narrative/tutorial_search",
|
this.messageBus?.unsubscribe(
|
||||||
this.onMessage
|
`/new_user_narrative/tutorial_search/${this.currentUser.id}`,
|
||||||
);
|
this.onMessage
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
|
@ -173,7 +173,11 @@ module DiscourseNarrativeBot
|
|||||||
topic = @post.topic
|
topic = @post.topic
|
||||||
post = topic.first_post
|
post = topic.first_post
|
||||||
|
|
||||||
MessageBus.publish("/new_user_narrative/tutorial_search", {}, user_ids: [@user.id])
|
MessageBus.publish(
|
||||||
|
"/new_user_narrative/tutorial_search/#{@user.id}",
|
||||||
|
{},
|
||||||
|
user_ids: [@user.id],
|
||||||
|
)
|
||||||
|
|
||||||
raw = <<~MD
|
raw = <<~MD
|
||||||
#{post.raw}
|
#{post.raw}
|
||||||
|
@ -551,7 +551,7 @@ RSpec.describe UserUpdater do
|
|||||||
context "when skip_new_user_tips is edited" do
|
context "when skip_new_user_tips is edited" do
|
||||||
it "updates seen_popups too" do
|
it "updates seen_popups too" do
|
||||||
messages =
|
messages =
|
||||||
MessageBus.track_publish("/user-tips") do
|
MessageBus.track_publish("/user-tips/#{user.id}") do
|
||||||
UserUpdater.new(Discourse.system_user, user).update(skip_new_user_tips: true)
|
UserUpdater.new(Discourse.system_user, user).update(skip_new_user_tips: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ RSpec.describe UserUpdater do
|
|||||||
context "when seen_popups is edited" do
|
context "when seen_popups is edited" do
|
||||||
it "publishes a message" do
|
it "publishes a message" do
|
||||||
messages =
|
messages =
|
||||||
MessageBus.track_publish("/user-tips") do
|
MessageBus.track_publish("/user-tips/#{user.id}") do
|
||||||
UserUpdater.new(Discourse.system_user, user).update(seen_popups: [1])
|
UserUpdater.new(Discourse.system_user, user).update(seen_popups: [1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user