FIX: Unsubscribe from topic presence when navigating between topics (#12198)

This PR fixes a bug where if you navigate from topic to another one (via suggested topics, notifications etc.), the previous topic is not unsubscribed from presence manager, which means if you visit lots of topics all the subscriptions will accumulate and can cause rate limit errors.

This bug is exposed by the loading slider we're currently experimenting with on Meta because we no longer have an intermediate state when navigating between topics which means the `willDestroyElement` hook that's responsible for unsubscribing is not called.
This commit is contained in:
Osama Sayegh 2021-02-24 23:14:38 +03:00 committed by GitHub
parent dc7e3fab50
commit bd709c89a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { inject as service } from "@ember/service";
export default Component.extend({
topic: null,
topicId: null,
presenceManager: service(),
@discourseComputed("topic.id")
@ -15,8 +16,17 @@ export default Component.extend({
shouldDisplay: gt("users.length", 0),
didReceiveAttrs() {
this._super(...arguments);
if (this.topicId) {
this.presenceManager.unsubscribe(this.topicId, TOPIC_TYPE);
}
this.set("topicId", this.get("topic.id"));
},
@on("didInsertElement")
subscribe() {
this.set("topicId", this.get("topic.id"));
this.presenceManager.subscribe(this.get("topic.id"), TOPIC_TYPE);
},