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.
This commit is contained in:
parent
fb5c3c7021
commit
7eb502c036
2 changed files with 2 additions and 2 deletions
|
@ -24,7 +24,7 @@ module Issuable
|
||||||
|
|
||||||
scope :authored, ->(user) { where(author_id: user) }
|
scope :authored, ->(user) { where(author_id: user) }
|
||||||
scope :assigned_to, ->(u) { where(assignee_id: u.id)}
|
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 :assigned, -> { where("assignee_id IS NOT NULL") }
|
||||||
scope :unassigned, -> { where("assignee_id IS NULL") }
|
scope :unassigned, -> { where("assignee_id IS NULL") }
|
||||||
scope :of_projects, ->(ids) { where(project_id: ids) }
|
scope :of_projects, ->(ids) { where(project_id: ids) }
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Event < ActiveRecord::Base
|
||||||
after_create :reset_project_activity
|
after_create :reset_project_activity
|
||||||
|
|
||||||
# Scopes
|
# Scopes
|
||||||
scope :recent, -> { order(created_at: :desc) }
|
scope :recent, -> { reorder(id: :desc) }
|
||||||
scope :code_push, -> { where(action: PUSHED) }
|
scope :code_push, -> { where(action: PUSHED) }
|
||||||
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
|
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
|
||||||
scope :with_associations, -> { includes(project: :namespace) }
|
scope :with_associations, -> { includes(project: :namespace) }
|
||||||
|
|
Loading…
Reference in a new issue