discourse/app/assets/javascripts
Martin Brennan e15c86e8c5
DEV: Topic tracking state improvements (#13218)
I merged this PR in yesterday, finally thinking this was done https://github.com/discourse/discourse/pull/12958 but then a wild performance regression occurred. These are the problem methods:

1aa20bd681/app/serializers/topic_tracking_state_serializer.rb (L13-L21)

Turns out date comparison is super expensive on the backend _as well as_ the frontend.

The fix was to just move the `treat_as_new_topic_start_date` into the SQL query rather than using the slower `UserOption#treat_as_new_topic_start_date` method in ruby. After this change, 1% of the total time is spent with the `created_in_new_period` comparison instead of ~20%.

----

History:

Original PR which had to be reverted **https://github.com/discourse/discourse/pull/12555**. See the description there for what this PR is achieving, plus below.

The issue with the original PR is addressed in 92ef54f402

If you went to the `x unread` link for a tag Chrome would freeze up and possibly crash, or eventually unfreeze after nearly 10 mins. Other routes for unread/new were similarly slow. From profiling the issue was the `sync` function of `topic-tracking-state.js`, which calls down to `isNew` which in turn calls `moment`, a change I had made in the PR above. The time it takes locally with ~1400 topics in the tracking state is 2.3 seconds.

To solve this issue, I have moved these calculations for "created in new period" and "unread not too old" into the tracking state serializer.

When I was looking at the profiler I also noticed this issue which was just compounding the problem. Every time we modify topic tracking state we recalculate the sidebar tracking/everything/tag counts. However this calls `forEachTracked` and `countTags` which can be quite expensive as they go through the whole tracking state (and were also calling the removed moment functions).

I added some logs and this was being called 30 times when navigating to a new /unread route because  `sync` is being called from `build-topic-route` (one for each topic loaded due to pagination). So I just added a debounce here and it makes things even faster.

Finally, I changed topic tracking state to use a Map so our counts of the state keys is faster (Maps have .size whereas objects you have to do Object.keys(obj) which is O(n).)

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
2021-06-02 09:06:29 +10:00
..
admin DEV: Remove `cache` option from `ajax()` (#13142) 2021-05-31 14:41:35 +02:00
confirm-new-email DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
discourse DEV: Topic tracking state improvements (#13218) 2021-06-02 09:06:29 +10:00
discourse-common DEV: Update ember-cli across all in-repo addons (#13048) 2021-05-12 21:49:55 +02:00
discourse-hbr DEV: Update ember-cli across all in-repo addons (#13048) 2021-05-12 21:49:55 +02:00
discourse-widget-hbs DEV: Update ember-cli across all in-repo addons (#13048) 2021-05-12 21:49:55 +02:00
docs DEV: enforces eslint’s curly rule to the codebase (#10720) 2020-09-22 16:28:28 +02:00
ember-addons DEV: Remove ember-addons (#9559) 2020-04-28 10:14:49 -04:00
locales DEV: Correct typos and spelling mistakes (#12812) 2021-05-21 11:43:47 +10:00
pretty-text DEV: Remove `cache` option from `ajax()` (#13142) 2021-05-31 14:41:35 +02:00
select-kit FEATURE: Show all categories in composer (#13213) 2021-05-31 20:50:23 +02:00
truth-helpers DEV: Update ember-cli across all in-repo addons (#13048) 2021-05-12 21:49:55 +02:00
wizard FIX: Wizard locale change wasn't applying to some elements (#12915) 2021-04-30 12:14:16 -04:00
activate-account.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
admin.js.erb FIX: Load .js files from plugins in qunit testing env (#11304) 2020-12-03 10:25:42 -06:00
app-boot.js REFACTOR: Sync up master with changes for Ember-CLI (#11671) 2021-01-12 10:13:21 -05:00
application.js FEATURE: Improve group email settings UI (#13083) 2021-05-28 09:28:18 +10:00
auto-redirect.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
browser-detect.js Improve support for old browsers (#9515) 2020-04-29 21:40:21 +03:00
browser-update.js FIX: browser-update should work with old browsers (#12436) 2021-03-18 19:09:01 +02:00
discourse-loader.js DEV: Add more @ember modules for plugins compatibility with Ember CLI (#11972) 2021-02-04 16:26:06 +03:00
discourse-shims.js FIX: Update non-Ember CLI ember-buffered-proxy (#13227) 2021-06-01 16:49:03 +02:00
embed-application.js DEV: prettier 2.2.1 (#11862) 2021-01-27 12:39:20 +01:00
ember_include.js.erb
ember_jquery.js Revert "Revert "DEV: Import `MessageBus` from `message-bus-client` instead of globals"" 2020-05-28 08:42:36 -04:00
env.js
google-tag-manager.js FEATURE: Implement nonces for Google Tag Manager integration (#12531) 2021-03-26 11:19:31 -04:00
google-universal-analytics-v3.js FEATURE: Add Google Universal Analytics v4 as an option (#11123) 2020-11-06 14:15:36 -06:00
google-universal-analytics-v4.js FEATURE: Add Google Universal Analytics v4 as an option (#11123) 2020-11-06 14:15:36 -06:00
handlebars-shim.js FIX: It seems sometimes shims are evaluated by older JS engines (#11813) 2021-01-22 10:41:01 -05:00
main_include_admin.js REFACTOR: Support bundling our `admin` section as an ember addon 2020-09-22 15:14:29 -04:00
markdown-it-bundle.js REFACTOR: Do not rely on module order for discourse-markdown loading 2020-09-18 13:31:55 -04:00
onpopstate-handler.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
package.json FIX: Make truth-helpers work in Ember CLI (#13044) 2021-05-12 17:52:36 +02:00
polyfills.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
pretty-text-bundle.js FIX: pretty text allow list (#10977) 2020-10-28 13:22:06 +11:00
print-page.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
service-worker.js.erb DEV: debug: false for service workers to stop log spam via workbox (#12093) 2021-02-16 14:01:19 +10:00
set-prototype-polyfill.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
start-discourse.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
template_include.js DEV: Support for `import Handlebars from 'handlebars'`; (#9600) 2020-04-30 16:41:02 -04:00
test-shims.js DEV: Migrate to Ember CLI (#11932) 2021-02-03 14:22:20 -05:00
vendor.js DEV: Remove `ember_jquery` in most situations (#13237) 2021-06-01 15:32:51 -04:00
widget-runtime.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
wizard-application.js DEV: implements some of ember-truth-helpers (#12667) 2021-04-12 11:40:00 +02:00
wizard-shims.js FIX: adds shims for popper in wizard (#10658) 2020-09-14 12:33:14 -04:00
wizard-start.js DEV: apply new coding standards (#10592) 2020-09-04 13:42:47 +02:00
wizard-vendor.js DEV: Remove `ember_jquery` in most situations (#13237) 2021-06-01 15:32:51 -04:00
yarn.lock DEV: Add peer dependencies (#13132) 2021-05-25 18:39:40 +02:00