From 87ac590078c6c219a8afb6feac6e41d75dca1287 Mon Sep 17 00:00:00 2001
From: catatsuy <catatsuy@catatsuy.org>
Date: Tue, 16 Jun 2015 21:22:06 +0900
Subject: [PATCH] 'created_at DESC' is performed twice

If you are already sorting in descending order in the created_at,
it is run twice when you run the .recent.
It has passed in the string 'created_at DESC'.
Ruby on Rails is directly given to the SQL.
It is a slow query in MySQL.
---
 app/models/event.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/models/event.rb b/app/models/event.rb
index c9a88ffa8e0..78f16c6304e 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -44,7 +44,7 @@ class Event < ActiveRecord::Base
   after_create :reset_project_activity
 
   # Scopes
-  scope :recent, -> { order("created_at DESC") }
+  scope :recent, -> { order(created_at: :desc) }
   scope :code_push, -> { where(action: PUSHED) }
   scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
   scope :with_associations, -> { includes(project: :namespace) }
-- 
GitLab