FEATURE: Conditionally force optimized category style (#29473)

The `categories_only_optimized` category page style has been introduced
in commit d37a0d401c. This commit makes
sure that style is enforced for users who can see over 1000 categories
in order to keep `/categories` page functional.
This commit is contained in:
Bianca Nenciu
2024-10-30 16:46:56 +02:00
committed by GitHub
parent 2e3f1a6a62
commit 430c42acde
5 changed files with 33 additions and 10 deletions

View File

@@ -4,6 +4,9 @@ class CategoryList
CATEGORIES_PER_PAGE = 20
SUBCATEGORIES_PER_CATEGORY = 5
# Maximum number of categories before the optimized category page style is enforced
MAX_UNOPTIMIZED_CATEGORIES = 1000
include ActiveModel::Serialization
cattr_accessor :preloaded_topic_custom_fields
@@ -139,9 +142,14 @@ class CategoryList
query = query.where(parent_category_id: @options[:parent_category_id])
end
style =
if Category.secured(@guardian).count > MAX_UNOPTIMIZED_CATEGORIES
"categories_only_optimized"
else
SiteSetting.desktop_category_page_style
end
page = [1, @options[:page].to_i].max
if SiteSetting.desktop_category_page_style == "categories_only_optimized" ||
@guardian.can_lazy_load_categories?
if style == "categories_only_optimized" || @guardian.can_lazy_load_categories?
query = query.limit(CATEGORIES_PER_PAGE).offset((page - 1) * CATEGORIES_PER_PAGE)
elsif page > 1
# Pagination is supported only when lazy load is enabled. If it is not,