Skip to content

Commit

Permalink
PERF: Tame eager-loading of category definition topic URL
Browse files Browse the repository at this point in the history
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
  • Loading branch information
riking committed Sep 11, 2014
1 parent 61bcde6 commit 056249c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/topic_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def default_results(options={})
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
Expand Down

0 comments on commit 056249c

Please sign in to comment.