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:
parent
dc7e3fab50
commit
bd709c89a7
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue