mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user