mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 12:23:45 +08:00
1106e4ad09
What is the problem? The main problem here is that we were incorrectly registering the same `onStateChange` callback with `TopicTrackingState` each time a user reads a post. When a user reads a post, the state in `TopicTrackingState` is updated and it triggers all the `onStateChange` callbacks which have been registered. In the `CommunitySection` class, we register a callback which would then call the `onTopicTrackingStateChange` method for each link in the class. For the `EverythingSectionLink` class, this would lookup the state in `TopicTrackingState` to get a new count of unread/new topics and update the `totalUnread` and `totalNew` properties which are tracked. For some reason that I have yet to figure out, updating the either of the tracked properties would result in Ember rerendering the entire `{{#each this.sections as |section|}}` in `component/sidebar/user/custom-sections.hbs` template. Note that `this.sections` refers to a `@cached` getter in the `SidebarUserCustomSections` class. The problem is that the `sections` getter is initializing a new bunch of sidebar sections related classes without calling the teardown function. As a result, we end up registering new `onStateChange` callbacks in `TopicTrackingState` in `CommunitySection` without removing the old ones. Over time, the number of callbacks build up and we end up slowing down the application. While we do not know the reason why defining a getter for the `sections` is causing the entire block to re-render, I realized that it is dangerous to use a getter for `sections` here since we have very little control on when the cached is broken. Instead, I moved the `sections` getter to a tracked property instead where the property is updated via `appEvents`. With this change, updating the tracked properties in `EverythingSectionLink` is no longer triggering a complete re-render of the said block above. We also now call `teardown` on the section objects that has been initialised before updating the `sections` property. |
||
---|---|---|
.. | ||
images | ||
javascripts | ||
stylesheets |