diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-11 15:19:09 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-11 15:19:09 +0000 |
commit | dfd8ae8a8457e08f3e2da7732c59dbf70e541460 (patch) | |
tree | 206c28ab535a4b879b9f84110e7e925ac33b2d02 | |
parent | fb5c3c70216d7a1151fa4ec767cd034bbb435587 (diff) | |
parent | 7eb502c036f412e9e802600cd67c6520a1f3bff1 (diff) | |
download | gitlab-ce-dfd8ae8a8457e08f3e2da7732c59dbf70e541460.tar.gz |
Merge branch 'recent-scope-ordering' into 'master'
Change "recent" scopes to sort by "id"
These scopes can just sort by the "id" column in descending order to
achieve the same result. An added benefit is being able to perform a
backwards index scan (depending on the rest of the final query) instead
of having to actually sort data.
See merge request !1788
-rw-r--r-- | app/models/concerns/issuable.rb | 2 | ||||
-rw-r--r-- | app/models/event.rb | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 5e964f04ef5..492a026add9 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -24,7 +24,7 @@ module Issuable scope :authored, ->(user) { where(author_id: user) } scope :assigned_to, ->(u) { where(assignee_id: u.id)} - scope :recent, -> { order("created_at DESC") } + scope :recent, -> { reorder(id: :desc) } scope :assigned, -> { where("assignee_id IS NOT NULL") } scope :unassigned, -> { where("assignee_id IS NULL") } scope :of_projects, ->(ids) { where(project_id: ids) } diff --git a/app/models/event.rb b/app/models/event.rb index 47600c57e35..bf64ac29d32 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -45,7 +45,7 @@ class Event < ActiveRecord::Base after_create :reset_project_activity # Scopes - scope :recent, -> { order(created_at: :desc) } + scope :recent, -> { reorder(id: :desc) } scope :code_push, -> { where(action: PUSHED) } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } scope :with_associations, -> { includes(project: :namespace) } |