FIX: N+1 query for shared drafts

This commit is contained in:
Robin Ward 2018-03-22 16:24:30 -04:00
parent cbbeedf53b
commit 41fc8e32e2
1 changed files with 5 additions and 0 deletions

View File

@ -607,6 +607,11 @@ class TopicQuery
result = apply_ordering(result, options)
result = result.listable_topics.includes(:category)
# Avoid N+1 for shared drafts
if category_id && category_id == SiteSetting.shared_drafts_category.to_i
result = result.includes(:shared_draft)
end
if options[:destination_category_id]
destination_category_id = get_category_id(options[:destination_category_id])
result = result.includes(:shared_draft).where("shared_drafts.category_id" => destination_category_id)