From c6bd6371f22df6a5cada739d90ae7d474b3d4160 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 5 Apr 2013 16:09:27 -0400 Subject: [PATCH] Exclude recently made invisible topics from the categories list. Also remove a couple n+1 queries. --- app/models/category_list.rb | 3 ++- app/serializers/category_detailed_serializer.rb | 13 +++++++++++-- app/serializers/category_topic_serializer.rb | 1 - 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 60ff863de..36cd37e88 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -7,7 +7,8 @@ class CategoryList @categories = Category .includes(featured_topics: [:category]) .includes(:featured_users) - .order('topics_week desc, topics_month desc, topics_year desc') + .where('topics.visible' => true) + .order('categories.topics_week desc, categories.topics_month desc, categories.topics_year desc') .to_a # Support for uncategorized topics diff --git a/app/serializers/category_detailed_serializer.rb b/app/serializers/category_detailed_serializer.rb index 28afff806..9e99f722e 100644 --- a/app/serializers/category_detailed_serializer.rb +++ b/app/serializers/category_detailed_serializer.rb @@ -1,6 +1,15 @@ -class CategoryDetailedSerializer < CategorySerializer +class CategoryDetailedSerializer < ApplicationSerializer - attributes :topic_count, :topics_week, :topics_month, :topics_year + attributes :id, + :name, + :color, + :text_color, + :slug, + :topic_count, + :topics_week, + :topics_month, + :topics_year, + :description has_many :featured_users, serializer: BasicUserSerializer has_many :featured_topics, serializer: CategoryTopicSerializer, embed: :objects, key: :topics diff --git a/app/serializers/category_topic_serializer.rb b/app/serializers/category_topic_serializer.rb index fa9da60e9..7bd91d8b3 100644 --- a/app/serializers/category_topic_serializer.rb +++ b/app/serializers/category_topic_serializer.rb @@ -3,7 +3,6 @@ require_dependency 'pinned_check' class CategoryTopicSerializer < ListableTopicSerializer attributes :visible, :closed, :archived, :pinned - has_one :category def pinned PinnedCheck.new(object, object.user_data).pinned?