PERF: Tame eager-loading of category definition topic URL

With this change, the EXPLAIN on the topic query is reduced in cost, and
script/bench.rb results are improved.

Explain topic query, cost at root level:

cost=641.84..641.92 --> cost=570.03..570.11

script/bench.rb result, 50th percentile:

BEFORE
---

categories_admin: 95
home_admin: 80
topic_admin: 33
categories: 71
home: 51
topic: 15

AFTER
---

categories_admin: 78
home_admin: 58
topic_admin: 49
categories: 40
home: 34
topic: 30
This commit is contained in:
riking 2014-09-10 19:55:10 -07:00
parent 61bcde6284
commit 056249cc93
1 changed files with 1 additions and 1 deletions

View File

@ -246,7 +246,7 @@ class TopicQuery
end
result = apply_ordering(result, options)
result = result.listable_topics.includes(category: :topic_only_relative_url)
result = result.listable_topics.includes(:category)
result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
# Don't include the category topics if excluded