'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.
This commit is contained in:
catatsuy 2015-06-16 21:22:06 +09:00
parent 7c42aaa576
commit 87ac590078

View file

@ -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) }