FIX: N+1 query in suggested topics list.

This commit is contained in:
Guo Xiang Tan 2017-05-22 18:05:38 +08:00
parent ded9575c32
commit 604aaf8686
2 changed files with 4 additions and 4 deletions

View File

@ -46,8 +46,6 @@ class TopicList
if @opts[:category]
@category = Category.find_by(id: @opts[:category_id])
end
preloaded_custom_fields << DiscourseTagging::TAGS_FIELD_NAME if SiteSetting.tagging_enabled
end
def tags

View File

@ -787,10 +787,12 @@ class TopicQuery
end
def base_messages
Topic
query = Topic
.where('topics.archetype = ?', Archetype.private_message)
.joins("LEFT JOIN topic_users tu ON topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i}")
.order('topics.bumped_at DESC')
query = query.includes(:tags) if SiteSetting.tagging_enabled
query.order('topics.bumped_at DESC')
end
def random_suggested(topic, count, excluded_topic_ids=[])