Commit 4e6c1ef6 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'sh-add-weight-simple-sort' into 'master'

Optimize issue search when sorting by weight

See merge request gitlab-org/gitlab!24208
parents bfd14dbd 90a01bbd
---
title: Optimize issue search when sorting by weight
merge_request: 24208
author:
type: performance
......@@ -145,7 +145,20 @@ module EE
end
class_methods do
# override
extend ::Gitlab::Utils::Override
override :simple_sorts
def simple_sorts
super.merge(
{
'weight' => -> { order_weight_asc.with_order_id_desc },
'weight_asc' => -> { order_weight_asc.with_order_id_desc },
'weight_desc' => -> { order_weight_desc.with_order_id_desc }
}
)
end
override :sort_by_attribute
def sort_by_attribute(method, excluded_labels: [])
case method.to_s
when 'weight', 'weight_asc' then order_weight_asc.with_order_id_desc
......
......@@ -210,6 +210,15 @@ describe Issue do
end
end
describe '.simple_sorts' 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
weight weight_asc weight_desc))
end
end
describe '#sort' do
let(:project) { create(:project) }
......
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