mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 23:23:49 +08:00
PERF: Use simpler serializer for search, eager load post users
This commit is contained in:
parent
b2134aa173
commit
c1125c8649
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user