mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: category list order using category featured topics (#7283)
This commit is contained in:
@@ -43,6 +43,19 @@ class CategoryList
|
||||
"categories_list".freeze
|
||||
end
|
||||
|
||||
def self.order_categories(categories)
|
||||
if SiteSetting.fixed_category_positions
|
||||
categories.order(:position, :id)
|
||||
else
|
||||
allowed_category_ids = categories.pluck(:id) << nil # `nil` is necessary to include categories without any associated topics
|
||||
categories.left_outer_joins(:featured_topics)
|
||||
.where(topics: { category_id: allowed_category_ids })
|
||||
.group('categories.id')
|
||||
.order("max(topics.bumped_at) DESC NULLS LAST")
|
||||
.order('categories.id ASC')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_relevant_topics
|
||||
@@ -75,11 +88,7 @@ class CategoryList
|
||||
|
||||
@categories = @categories.where("categories.parent_category_id = ?", @options[:parent_category_id].to_i) if @options[:parent_category_id].present?
|
||||
|
||||
if SiteSetting.fixed_category_positions
|
||||
@categories = @categories.order(:position, :id)
|
||||
else
|
||||
@categories = @categories.includes(:latest_post).order("posts.created_at DESC NULLS LAST").order('categories.id ASC')
|
||||
end
|
||||
@categories = self.class.order_categories(@categories)
|
||||
|
||||
@categories = @categories.to_a
|
||||
|
||||
|
||||
Reference in New Issue
Block a user