Commit 9dacc3bc authored by Yorick Peterse's avatar Yorick Peterse

Sort by ID when sorting using "Recently created"

Sorting by "id" has the same effect as sorting by created_at while
performing far better and without the need of an extra index (in case
one wanted to speed up sorting by "created_at").

Sorting by "Recently updated" still uses the physical "updated_at"
column as there's no way to use the "id" column for this instead.
parent 7a240397
...@@ -286,7 +286,7 @@ class ApplicationController < ActionController::Base ...@@ -286,7 +286,7 @@ class ApplicationController < ActionController::Base
end end
def set_filters_params def set_filters_params
params[:sort] ||= 'created_desc' params[:sort] ||= 'id_desc'
params[:scope] = 'all' if params[:scope].blank? params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank? params[:state] = 'opened' if params[:state].blank?
......
...@@ -63,11 +63,11 @@ module SortingHelper ...@@ -63,11 +63,11 @@ module SortingHelper
end end
def sort_value_oldest_created def sort_value_oldest_created
'created_asc' 'id_asc'
end end
def sort_value_recently_created def sort_value_recently_created
'created_desc' 'id_desc'
end end
def sort_value_milestone_soon def sort_value_milestone_soon
......
...@@ -11,6 +11,7 @@ module Sortable ...@@ -11,6 +11,7 @@ module Sortable
default_scope { order_id_desc } default_scope { order_id_desc }
scope :order_id_desc, -> { reorder(id: :desc) } scope :order_id_desc, -> { reorder(id: :desc) }
scope :order_id_asc, -> { reorder(id: :asc) }
scope :order_created_desc, -> { reorder(created_at: :desc) } scope :order_created_desc, -> { reorder(created_at: :desc) }
scope :order_created_asc, -> { reorder(created_at: :asc) } scope :order_created_asc, -> { reorder(created_at: :asc) }
scope :order_updated_desc, -> { reorder(updated_at: :desc) } scope :order_updated_desc, -> { reorder(updated_at: :desc) }
...@@ -28,6 +29,8 @@ module Sortable ...@@ -28,6 +29,8 @@ module Sortable
when 'updated_desc' then order_updated_desc when 'updated_desc' then order_updated_desc
when 'created_asc' then order_created_asc when 'created_asc' then order_created_asc
when 'created_desc' then order_created_desc when 'created_desc' then order_created_desc
when 'id_desc' then order_id_desc
when 'id_asc' then order_id_asc
else else
all all
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment