FIX: Ensure the top 6 categories are shown in the user summary (#12691)

Previously it would pluck 6 categories which the user had posted in, **then** order them. To select the **top 6** categories, we need to perform the ordering in the SQL query before the LIMIT
This commit is contained in:
David Taylor
2021-04-15 11:05:03 +01:00
committed by GitHub
parent 3326d1ff73
commit c60668a052
2 changed files with 21 additions and 1 deletions

View File

@ -145,7 +145,7 @@ class UserSummary
top_categories = {}
Category.where(id: post_count_query.limit(MAX_SUMMARY_RESULTS).pluck('category_id'))
Category.where(id: post_count_query.order("count(*) DESC").limit(MAX_SUMMARY_RESULTS).pluck('category_id'))
.pluck(:id, :name, :color, :text_color, :slug, :read_restricted, :parent_category_id)
.each do |c|
top_categories[c[0].to_i] = CategoryWithCounts.new(