Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bdba0946
Commit
bdba0946
authored
Sep 30, 2020
by
Alan Paruszewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem with sorting by case in GraphQL
parent
2ae6c5f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
lib/gitlab/graphql/pagination/keyset/order_info.rb
lib/gitlab/graphql/pagination/keyset/order_info.rb
+7
-0
spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb
spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb
+11
-0
No files found.
lib/gitlab/graphql/pagination/keyset/order_info.rb
View file @
bdba0946
...
@@ -94,6 +94,8 @@ module Gitlab
...
@@ -94,6 +94,8 @@ module Gitlab
[
order_value
.
expr
.
expressions
[
0
].
name
.
to_s
,
order_value
.
direction
,
order_value
.
expr
]
[
order_value
.
expr
.
expressions
[
0
].
name
.
to_s
,
order_value
.
direction
,
order_value
.
expr
]
elsif
ordering_by_similarity?
(
order_value
)
elsif
ordering_by_similarity?
(
order_value
)
[
'similarity'
,
order_value
.
direction
,
order_value
.
expr
]
[
'similarity'
,
order_value
.
direction
,
order_value
.
expr
]
elsif
ordering_by_case?
(
order_value
)
[
order_value
.
expr
.
case
.
name
.
to_s
,
order_value
.
direction
,
order_value
.
expr
]
else
else
[
order_value
.
expr
.
name
,
order_value
.
direction
,
nil
]
[
order_value
.
expr
.
name
,
order_value
.
direction
,
nil
]
end
end
...
@@ -108,6 +110,11 @@ module Gitlab
...
@@ -108,6 +110,11 @@ module Gitlab
def
ordering_by_similarity?
(
order_value
)
def
ordering_by_similarity?
(
order_value
)
Gitlab
::
Database
::
SimilarityScore
.
order_by_similarity?
(
order_value
)
Gitlab
::
Database
::
SimilarityScore
.
order_by_similarity?
(
order_value
)
end
end
# determine if ordering using CASE
def
ordering_by_case?
(
order_value
)
order_value
.
expr
.
is_a?
(
Arel
::
Nodes
::
Case
)
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/graphql/pagination/keyset/order_info_spec.rb
View file @
bdba0946
...
@@ -63,6 +63,17 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do
...
@@ -63,6 +63,17 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::OrderInfo do
expect
(
order_list
.
first
.
sort_direction
).
to
eq
:desc
expect
(
order_list
.
first
.
sort_direction
).
to
eq
:desc
end
end
end
end
context
'when ordering by CASE'
,
:aggregate_failuers
do
let
(
:relation
)
{
Project
.
order
(
Arel
::
Nodes
::
Case
.
new
(
Project
.
arel_table
[
:pending_delete
]).
when
(
true
).
then
(
100
).
else
(
1000
).
asc
)
}
it
'assigns the right attribute name, named function, and direction'
do
expect
(
order_list
.
count
).
to
eq
1
expect
(
order_list
.
first
.
attribute_name
).
to
eq
'pending_delete'
expect
(
order_list
.
first
.
named_function
).
to
be_kind_of
(
Arel
::
Nodes
::
Case
)
expect
(
order_list
.
first
.
sort_direction
).
to
eq
:asc
end
end
end
end
describe
'#validate_ordering'
do
describe
'#validate_ordering'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment