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.
This commit is contained in:
Alan Guo Xiang Tan
2023-07-04 11:36:39 +08:00
committed by GitHub
parent 6ae4d6cd4c
commit 82d6420e31
13 changed files with 268 additions and 68 deletions

View File

@@ -88,16 +88,6 @@ RSpec.describe "Editing sidebar tags navigation", type: :system do
include_examples "a user can edit the sidebar tags navigation", true
end
it "displays the all tags in the modal when `tags_listed_by_group` site setting is true" do
SiteSetting.tags_listed_by_group = true
visit "/latest"
modal = sidebar.click_edit_tags_button
expect(modal).to have_tag_checkboxes([tag1, tag2, tag3, tag4])
end
it "allows a user to filter the tags in the modal by the tag's name" do
visit "/latest"
@@ -186,4 +176,16 @@ RSpec.describe "Editing sidebar tags navigation", type: :system do
expect(modal).to have_tag_checkboxes([tag1, tag2, tag3, tag4])
end
it "loads more tags when the user scrolls views the last tag in the modal and there is more tags to load" do
stub_const(TagsController, "LIST_LIMIT", 2) do
visit "/latest"
expect(sidebar).to have_tags_section
modal = sidebar.click_edit_tags_button
expect(modal).to have_tag_checkboxes([tag1, tag2, tag3, tag4])
end
end
end