PERF: Use simpler serializer for search, eager load post users

This commit is contained in:
Robin Ward 2016-08-09 13:41:25 -04:00
parent b2134aa173
commit c1125c8649
2 changed files with 6 additions and 4 deletions

View File

@ -1,9 +1,8 @@
class SearchPostSerializer < PostSerializer class SearchPostSerializer < BasicPostSerializer
has_one :topic, serializer: TopicListItemSerializer has_one :topic, serializer: TopicListItemSerializer
attributes :like_count attributes :like_count, :blurb
attributes :blurb
def blurb def blurb
options[:result].blurb(object) options[:result].blurb(object)
end end

View File

@ -663,6 +663,7 @@ class Search
post_sql = "SELECT *, row_number() over() row_number FROM (#{post_sql}) xxx" post_sql = "SELECT *, row_number() over() row_number FROM (#{post_sql}) xxx"
posts = Post.includes(:topic => :category) 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") .joins("JOIN (#{post_sql}) x ON x.id = posts.topic_id AND x.post_number = posts.post_number")
.order('row_number') .order('row_number')
@ -679,7 +680,9 @@ class Search
def topic_search def topic_search
if @search_context.is_a?(Topic) 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| posts.each do |post|
@results.add(post) @results.add(post)
end end