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
4c61c2aa
Commit
4c61c2aa
authored
Nov 25, 2019
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidy up assumption check
parent
dff3ba49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
18 deletions
+5
-18
lib/gitlab/pagination/keyset/pager.rb
lib/gitlab/pagination/keyset/pager.rb
+5
-18
No files found.
lib/gitlab/pagination/keyset/pager.rb
View file @
4c61c2aa
...
@@ -11,8 +11,8 @@ module Gitlab
...
@@ -11,8 +11,8 @@ module Gitlab
end
end
def
paginate
(
relation
)
def
paginate
(
relation
)
# Validate a
n assumption we're making (TODO: subject to be removed)
# Validate a
ssumption: The last two columns must match the page order_by
check_order!
(
relation
)
raise
"Page's order_by doesnt match the relation's order:
#{
present_order
}
vs
#{
page
.
order_by
}
"
unless
correct_order?
(
relation
)
# This performs the database query and retrieves records
# This performs the database query and retrieves records
# We retrieve one record more to check if we have data beyond this page
# We retrieve one record more to check if we have data beyond this page
...
@@ -43,23 +43,10 @@ module Gitlab
...
@@ -43,23 +43,10 @@ module Gitlab
@page
||=
request
.
page
@page
||=
request
.
page
end
end
def
order_by
(
rel
)
def
correct_order?
(
rel
)
rel
.
order_values
.
map
{
|
val
|
[
val
.
expr
.
name
,
val
.
direction
]
}
present_order
=
rel
.
order_values
.
map
{
|
val
|
[
val
.
expr
.
name
,
val
.
direction
]
}.
last
(
2
).
to_h
end
def
check_order!
(
rel
)
present_order
=
order_by
(
rel
).
last
(
2
).
to_h
if
to_sym_vals
(
page
.
order_by
)
!=
to_sym_vals
(
present_order
)
# The last two columns must match the page order_by
raise
"Page order_by doesnt match the relation
\'
s order:
#{
present_order
}
vs
#{
page
.
order_by
}
"
end
end
def
to_sym_vals
(
hash
)
page
.
order_by
.
with_indifferent_access
==
present_order
.
with_indifferent_access
hash
.
each_with_object
({})
do
|
(
k
,
v
),
h
|
h
[
k
&
.
to_sym
]
=
v
&
.
to_sym
end
end
end
end
end
end
end
...
...
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