Commit 22399004 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'sh-add-due-date-simple-sort' into 'master'

Optimize issue search when sorting by due date and position

See merge request gitlab-org/gitlab!24217
parents f97a383f b9937fe6
......@@ -147,6 +147,20 @@ class Issue < ApplicationRecord
'project_id'
end
def self.simple_sorts
super.merge(
{
'closest_future_date' => -> { order_closest_future_date },
'closest_future_date_asc' => -> { order_closest_future_date },
'due_date' => -> { order_due_date_asc.with_order_id_desc },
'due_date_asc' => -> { order_due_date_asc.with_order_id_desc },
'due_date_desc' => -> { order_due_date_desc.with_order_id_desc },
'relative_position' => -> { order_relative_position_asc.with_order_id_desc },
'relative_position_asc' => -> { order_relative_position_asc.with_order_id_desc }
}
)
end
def self.sort_by_attribute(method, excluded_labels: [])
case method.to_s
when 'closest_future_date', 'closest_future_date_asc' then order_closest_future_date
......
---
title: Optimize issue search when sorting by due date and position
merge_request: 24217
author:
type: performance
......@@ -214,7 +214,9 @@ describe Issue do
it 'includes weight with other base keys' do
expect(Issue.simple_sorts.keys).to match_array(
%w(created_asc created_at_asc created_date created_desc created_at_desc
id_asc id_desc updated_desc updated_asc updated_at_asc updated_at_desc
closest_future_date closest_future_date_asc due_date due_date_asc due_date_desc
id_asc id_desc relative_position relative_position_asc
updated_desc updated_asc updated_at_asc updated_at_desc
weight weight_asc weight_desc))
end
end
......
......@@ -84,6 +84,16 @@ describe Issue do
end
end
describe '.simple_sorts' do
it 'includes all keys' do
expect(described_class.simple_sorts.keys).to include(
*%w(created_asc created_at_asc created_date created_desc created_at_desc
closest_future_date closest_future_date_asc due_date due_date_asc due_date_desc
id_asc id_desc relative_position relative_position_asc
updated_desc updated_asc updated_at_asc updated_at_desc))
end
end
describe '#order_by_position_and_priority' do
let(:project) { create :project }
let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
......
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