From 82d6420e31849a1d55414a7234492cf98ab0bda4 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 4 Jul 2023 11:36:39 +0800 Subject: [PATCH] PERF: Paginate loading of tags in edit nav menu tags modal (#22380) What is the problem? Before this change, we were relying on the `/tags` endpoint which returned all the tags that are visible to a give user on the site leading to potential performance problems. The attribute keys of the response also changes based on the `tags_listed_by_group` site setting. What is the fix? This commit fixes the problems listed above by creating a dedicate `#list` action in the `TagsController` to handle the listing of the tags in the edit navigation menu tags modal. This is because the `TagsController#index` action was created specifically for the `/tags` route and the response body does not really map well to what we need. The `TagsController#list` action added here is also much safer since the response is paginated and we avoid loading a whole bunch of tags upfront. --- .../discourse/app/adapters/list-tag.js | 7 + .../edit-navigation-menu/categories-modal.hbs | 1 + .../sidebar/edit-navigation-menu/modal.hbs | 2 +- .../edit-navigation-menu/tags-modal.hbs | 15 +- .../edit-navigation-menu/tags-modal.js | 87 ++++++----- .../sidebar-user-tags-section-test.js | 10 -- .../sidebar/edit-navigation-menu/modal.scss | 2 +- .../edit-navigation-menu/tags-modal.scss | 2 +- .../edit-navigation-menu/tags-modal.scss | 2 +- app/controllers/tags_controller.rb | 41 +++++ config/routes.rb | 1 + spec/requests/tags_controller_spec.rb | 144 ++++++++++++++++++ .../editing_sidebar_tags_navigation_spec.rb | 22 +-- 13 files changed, 268 insertions(+), 68 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/adapters/list-tag.js diff --git a/app/assets/javascripts/discourse/app/adapters/list-tag.js b/app/assets/javascripts/discourse/app/adapters/list-tag.js new file mode 100644 index 00000000000..7f89508e908 --- /dev/null +++ b/app/assets/javascripts/discourse/app/adapters/list-tag.js @@ -0,0 +1,7 @@ +import RESTAdapter from "discourse/adapters/rest"; + +export default class extends RESTAdapter { + pathFor(_store, _type, findArgs) { + return this.appendQueryParams("/tags/list", findArgs); + } +} diff --git a/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/categories-modal.hbs b/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/categories-modal.hbs index cab218e9d0f..0f508a99d83 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/categories-modal.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/categories-modal.hbs @@ -1,4 +1,5 @@ diff --git a/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.hbs b/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.hbs index 9f5089c0507..1d999e98f61 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/tags-modal.hbs @@ -1,4 +1,5 @@ {{else}} - {{#if (gt this.filteredTags.length 0)}} - {{#each this.filteredTags as |tag|}} -