From 056249cc93054e697e4bb6763839c7071594a12e Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 10 Sep 2014 19:55:10 -0700 Subject: [PATCH] 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 --- lib/topic_query.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index ceb341ba5ca..3af501558c9 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -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