From af467a16755d9d0b5cea325fd4503a5648ca5f8c Mon Sep 17 00:00:00 2001 From: Sam <sam.saffron@gmail.com> Date: Wed, 2 Oct 2013 13:05:03 +1000 Subject: [PATCH] 404 page had horrible perf, it was using "take" instead of limit. in such cases EVERY row is materialized and only after the limit is applied. So ... imagine what happens on a forum with 2,000,000 topics --- app/controllers/exceptions_controller.rb | 2 +- lib/topic_query.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exceptions_controller.rb b/app/controllers/exceptions_controller.rb index 55fb96172..6a81de159 100644 --- a/app/controllers/exceptions_controller.rb +++ b/app/controllers/exceptions_controller.rb @@ -1,5 +1,5 @@ class ExceptionsController < ApplicationController - skip_before_filter :check_xhr + skip_before_filter :check_xhr, :preload_json def not_found # centralize all rendering of 404 into app controller diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 26b5a14ba..c31dc24eb 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -65,12 +65,12 @@ class TopicQuery "CASE WHEN (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC" end - def top_viewed(max) - Topic.listable_topics.visible.secured.order('views desc').take(10) + def top_viewed(max = 10) + Topic.listable_topics.visible.secured.order('views desc').limit(max) end - def recent(max) - Topic.listable_topics.visible.secured.order('created_at desc').take(10) + def recent(max = 10) + Topic.listable_topics.visible.secured.order('created_at desc').limit(max) end end