Skip to content

A platform for community discussion. Free, open, simple.

FIX: Use the max_tag_search_results setting as the default limit for tag groups search (#33485)

Osama Sayegh4406926a8b0e
diff --git a/app/controllers/tag_groups_controller.rb b/app/controllers/tag_groups_controller.rb
index 6741838ee63..4fda59156e2 100644
--- a/app/controllers/tag_groups_controller.rb
+++ b/app/controllers/tag_groups_controller.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class TagGroupsController < ApplicationController
+ MAX_TAG_GROUPS_SEARCH_RESULTS = 1000 # matches the max limit for max_tag_search_results setting
+
requires_login except: [:search]
before_action :ensure_staff, except: [:search]
@@ -92,7 +94,10 @@ class TagGroupsController < ApplicationController
matches =
matches.order("name").limit(
- fetch_limit_from_params(default: 5, max: SiteSetting.max_tag_search_results),
+ fetch_limit_from_params(
+ default: SiteSetting.max_tag_search_results,
+ max: MAX_TAG_GROUPS_SEARCH_RESULTS,
+ ),
)
render json: {
diff --git a/config/site_settings.yml b/config/site_settings.yml
index e3f738a71a2..b40ebb550ac 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -3900,6 +3900,7 @@ tags:
client: true
default: 5
min: 1
+ max: 1000
area: "categories_and_tags"
max_tags_in_filter_list:
client: true
diff --git a/spec/requests/tag_groups_controller_spec.rb b/spec/requests/tag_groups_controller_spec.rb
index 2051771ddd0..1d7d830e99b 100644
--- a/spec/requests/tag_groups_controller_spec.rb
+++ b/spec/requests/tag_groups_controller_spec.rb
@@ -51,7 +51,18 @@ RSpec.describe TagGroupsController do
describe "when limit params is invalid" do
include_examples "invalid limit params",
"/tag_groups/filter/search.json",
- SiteSetting.max_tag_search_results
+ described_class::MAX_TAG_GROUPS_SEARCH_RESULTS
+ end
+
+ it "doesn't error when the max_tag_search_results setting is lowered from its default" do
+ tag_group = tag_group_with_permission(everyone, readonly)
+
+ SiteSetting.max_tag_search_results = 4
+
+ get "/tag_groups/filter/search.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["results"].size).to eq(1)
+ expect(response.parsed_body["results"].first["name"]).to eq(tag_group.name)
end
context "for anons" do