From 966e95761b57682bd38749f7fcc2e29b398d0542 Mon Sep 17 00:00:00 2001 From: Ahmad Al-kheat Date: Wed, 29 Apr 2015 20:25:44 -0400 Subject: [PATCH] Order by id Ordering by id is faster than ordering by created_at, because id is an index unlike created_at. And it gives the same results because id is automatically incremented. --- lib/comment_methods.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/comment_methods.rb b/lib/comment_methods.rb index f73322d..bee55b1 100644 --- a/lib/comment_methods.rb +++ b/lib/comment_methods.rb @@ -9,8 +9,8 @@ module Comment def self.included(comment_model) comment_model.extend Finders - comment_model.scope :in_order, -> { comment_model.order('created_at ASC') } - comment_model.scope :recent, -> { comment_model.reorder('created_at DESC') } + comment_model.scope :in_order, -> { comment_model.order('id ASC') } + comment_model.scope :recent, -> { comment_model.reorder('id DESC') } end def is_comment_type?(type)