diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-03 11:54:43 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-03 11:54:43 +0100 |
commit | 732f5380af5d688a152de9c5b4bb14ffb935dd2a (patch) | |
tree | b9ff6053f1487d1abd98a300be8d586ea946177b /app/models/concerns/sortable.rb | |
parent | 0df65909eff560f2d313c4034ed21a65d643a0c3 (diff) | |
download | gitlab-ce-732f5380af5d688a152de9c5b4bb14ffb935dd2a.tar.gz |
Only sort by IDs by default
Sorting by both "created_at" and "id" in descending order is not needed
as simply sorting by "id" in descending order will already sort rows
from new to old. Depending on the query and data involved sorting twice
can also introduce significant overhead.
Diffstat (limited to 'app/models/concerns/sortable.rb')
-rw-r--r-- | app/models/concerns/sortable.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb index 0ad2654867d..913c747a1c3 100644 --- a/app/models/concerns/sortable.rb +++ b/app/models/concerns/sortable.rb @@ -8,12 +8,12 @@ module Sortable included do # By default all models should be ordered # by created_at field starting from newest - default_scope { order(created_at: :desc, id: :desc) } + default_scope { order(id: :desc) } - scope :order_created_desc, -> { reorder(created_at: :desc, id: :desc) } - scope :order_created_asc, -> { reorder(created_at: :asc, id: :asc) } - scope :order_updated_desc, -> { reorder(updated_at: :desc, id: :desc) } - scope :order_updated_asc, -> { reorder(updated_at: :asc, id: :asc) } + scope :order_created_desc, -> { reorder(created_at: :desc) } + scope :order_created_asc, -> { reorder(created_at: :asc) } + scope :order_updated_desc, -> { reorder(updated_at: :desc) } + scope :order_updated_asc, -> { reorder(updated_at: :asc) } scope :order_name_asc, -> { reorder(name: :asc) } scope :order_name_desc, -> { reorder(name: :desc) } end |