From c1125c8649610a72e179416fae17d54104ebfef8 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 9 Aug 2016 13:41:25 -0400 Subject: [PATCH] PERF: Use simpler serializer for search, eager load post users --- app/serializers/search_post_serializer.rb | 5 ++--- lib/search.rb | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/serializers/search_post_serializer.rb b/app/serializers/search_post_serializer.rb index 1e92d044bec..098aa60dffb 100644 --- a/app/serializers/search_post_serializer.rb +++ b/app/serializers/search_post_serializer.rb @@ -1,9 +1,8 @@ -class SearchPostSerializer < PostSerializer +class SearchPostSerializer < BasicPostSerializer has_one :topic, serializer: TopicListItemSerializer - attributes :like_count + attributes :like_count, :blurb - attributes :blurb def blurb options[:result].blurb(object) end diff --git a/lib/search.rb b/lib/search.rb index 4cb1711c4e6..84b29700b90 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -663,6 +663,7 @@ class Search post_sql = "SELECT *, row_number() over() row_number FROM (#{post_sql}) xxx" posts = Post.includes(:topic => :category) + .includes(:user) .joins("JOIN (#{post_sql}) x ON x.id = posts.topic_id AND x.post_number = posts.post_number") .order('row_number') @@ -679,7 +680,9 @@ class Search def topic_search if @search_context.is_a?(Topic) - posts = posts_query(@limit).where('posts.topic_id = ?', @search_context.id).includes(:topic => :category) + posts = posts_query(@limit).where('posts.topic_id = ?', @search_context.id) + .includes(:topic => :category) + .includes(:user) posts.each do |post| @results.add(post) end