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
74e7ec90
Commit
74e7ec90
authored
Jan 06, 2020
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove end_reached? from Page
We don't need this anymore.
parent
619d5c95
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
33 deletions
+15
-33
lib/gitlab/pagination/keyset/page.rb
lib/gitlab/pagination/keyset/page.rb
+3
-10
lib/gitlab/pagination/keyset/pager.rb
lib/gitlab/pagination/keyset/pager.rb
+3
-3
lib/gitlab/pagination/keyset/request_context.rb
lib/gitlab/pagination/keyset/request_context.rb
+0
-2
spec/lib/gitlab/pagination/keyset/page_spec.rb
spec/lib/gitlab/pagination/keyset/page_spec.rb
+2
-9
spec/lib/gitlab/pagination/keyset/pager_spec.rb
spec/lib/gitlab/pagination/keyset/pager_spec.rb
+5
-7
spec/lib/gitlab/pagination/keyset/request_context_spec.rb
spec/lib/gitlab/pagination/keyset/request_context_spec.rb
+2
-2
No files found.
lib/gitlab/pagination/keyset/page.rb
View file @
74e7ec90
...
...
@@ -11,14 +11,13 @@ module Gitlab
# Maximum number of records for a page
MAXIMUM_PAGE_SIZE
=
100
attr_accessor
:lower_bounds
,
:end_reached
attr_accessor
:lower_bounds
attr_reader
:order_by
def
initialize
(
order_by:
{},
lower_bounds:
nil
,
per_page:
DEFAULT_PAGE_SIZE
,
end_reached:
false
)
def
initialize
(
order_by:
{},
lower_bounds:
nil
,
per_page:
DEFAULT_PAGE_SIZE
)
@order_by
=
order_by
.
symbolize_keys
@lower_bounds
=
lower_bounds
&
.
symbolize_keys
@per_page
=
per_page
@end_reached
=
end_reached
end
# Number of records to return per page
...
...
@@ -28,17 +27,11 @@ module Gitlab
[
@per_page
,
MAXIMUM_PAGE_SIZE
].
min
end
# Determine whether this page indicates the end of the collection
def
end_reached?
@end_reached
end
# Construct a Page for the next page
# Uses identical order_by/per_page information for the next page
def
next
(
lower_bounds
,
end_reached
)
def
next
(
lower_bounds
)
dup
.
tap
do
|
next_page
|
next_page
.
lower_bounds
=
lower_bounds
&
.
symbolize_keys
next_page
.
end_reached
=
end_reached
end
end
end
...
...
lib/gitlab/pagination/keyset/pager.rb
View file @
74e7ec90
...
...
@@ -24,10 +24,10 @@ module Gitlab
private
def
apply_headers
(
last_record_in_page
)
end_reached
=
last_record_in_page
.
nil?
lower_bounds
=
last_record_in_page
&
.
slice
(
page
.
order_by
.
keys
)
return
unless
last_record_in_page
next_page
=
page
.
next
(
lower_bounds
,
end_reached
)
lower_bounds
=
last_record_in_page
&
.
slice
(
page
.
order_by
.
keys
)
next_page
=
page
.
next
(
lower_bounds
)
request
.
apply_headers
(
next_page
)
end
...
...
lib/gitlab/pagination/keyset/request_context.rb
View file @
74e7ec90
...
...
@@ -68,8 +68,6 @@ module Gitlab
end
def
pagination_links
(
next_page
)
return
if
next_page
.
end_reached?
%(<#{page_href(next_page)}>; rel="next")
end
...
...
spec/lib/gitlab/pagination/keyset/page_spec.rb
View file @
74e7ec90
...
...
@@ -30,16 +30,14 @@ describe Gitlab::Pagination::Keyset::Page do
end
describe
'#next'
do
let
(
:page
)
{
described_class
.
new
(
order_by:
order_by
,
lower_bounds:
lower_bounds
,
per_page:
per_page
,
end_reached:
end_reached
)
}
subject
{
page
.
next
(
new_lower_bounds
,
new_end_reached
)
}
let
(
:page
)
{
described_class
.
new
(
order_by:
order_by
,
lower_bounds:
lower_bounds
,
per_page:
per_page
)
}
subject
{
page
.
next
(
new_lower_bounds
)
}
let
(
:order_by
)
{
{
id: :desc
}
}
let
(
:lower_bounds
)
{
{
id:
42
}
}
let
(
:per_page
)
{
10
}
let
(
:end_reached
)
{
false
}
let
(
:new_lower_bounds
)
{
{
id:
21
}
}
let
(
:new_end_reached
)
{
true
}
it
'copies over order_by'
do
expect
(
subject
.
order_by
).
to
eq
(
page
.
order_by
)
...
...
@@ -57,10 +55,5 @@ describe Gitlab::Pagination::Keyset::Page do
expect
(
subject
.
lower_bounds
).
to
eq
(
new_lower_bounds
)
expect
(
page
.
lower_bounds
).
to
eq
(
lower_bounds
)
end
it
'sets end_reached only on new instance'
do
expect
(
subject
.
end_reached?
).
to
eq
(
new_end_reached
)
expect
(
page
.
end_reached?
).
to
eq
(
end_reached
)
end
end
end
spec/lib/gitlab/pagination/keyset/pager_spec.rb
View file @
74e7ec90
...
...
@@ -41,7 +41,7 @@ describe Gitlab::Pagination::Keyset::Pager do
it
'passes information about next page to request'
do
lower_bounds
=
records
.
last
.
slice
(
:id
)
expect
(
page
).
to
receive
(
:next
).
with
(
lower_bounds
,
false
).
and_return
(
next_page
)
expect
(
page
).
to
receive
(
:next
).
with
(
lower_bounds
).
and_return
(
next_page
)
expect
(
request
).
to
receive
(
:apply_headers
).
with
(
next_page
)
subject
...
...
@@ -51,9 +51,9 @@ describe Gitlab::Pagination::Keyset::Pager do
let
(
:relation
)
{
Project
.
where
(
'id > ?'
,
Project
.
maximum
(
:id
)
-
page
.
per_page
).
order
(
id: :asc
)
}
it
'indicates there is another (likely empty) page'
do
expect
(
request
).
to
receive
(
:apply_headers
)
do
|
next_page
|
expect
(
next_page
.
end_reached?
).
to
be_falsey
e
nd
lower_bounds
=
records
.
last
.
slice
(
:id
)
expect
(
page
).
to
receive
(
:next
).
with
(
lower_bounds
).
and_return
(
next_page
)
e
xpect
(
request
).
to
receive
(
:apply_headers
).
with
(
next_page
)
subject
end
...
...
@@ -63,9 +63,7 @@ describe Gitlab::Pagination::Keyset::Pager do
let
(
:relation
)
{
Project
.
where
(
'id > ?'
,
Project
.
maximum
(
:id
)
+
1
).
order
(
id: :asc
)
}
it
'indicates this is the last page'
do
expect
(
request
).
to
receive
(
:apply_headers
)
do
|
next_page
|
expect
(
next_page
.
end_reached?
).
to
be_truthy
end
expect
(
request
).
not_to
receive
(
:apply_headers
)
subject
end
...
...
spec/lib/gitlab/pagination/keyset/request_context_spec.rb
View file @
74e7ec90
...
...
@@ -53,7 +53,7 @@ describe Gitlab::Pagination::Keyset::RequestContext do
let
(
:request
)
{
double
(
'request'
,
url:
"http://
#{
Gitlab
.
config
.
gitlab
.
host
}
/api/v4/projects?foo=bar"
)
}
let
(
:params
)
{
{
foo:
'bar'
}
}
let
(
:request_context
)
{
double
(
'request context'
,
params:
params
,
request:
request
)
}
let
(
:next_page
)
{
double
(
'next page'
,
order_by:
{
id: :asc
},
lower_bounds:
{
id:
42
}
,
end_reached?:
false
)
}
let
(
:next_page
)
{
double
(
'next page'
,
order_by:
{
id: :asc
},
lower_bounds:
{
id:
42
})
}
subject
{
described_class
.
new
(
request_context
).
apply_headers
(
next_page
)
}
...
...
@@ -92,7 +92,7 @@ describe Gitlab::Pagination::Keyset::RequestContext do
end
context
'with descending order'
do
let
(
:next_page
)
{
double
(
'next page'
,
order_by:
{
id: :desc
},
lower_bounds:
{
id:
42
}
,
end_reached?:
false
)
}
let
(
:next_page
)
{
double
(
'next page'
,
order_by:
{
id: :desc
},
lower_bounds:
{
id:
42
})
}
it
'sets Links header with a link to the next page'
do
orig_uri
=
URI
.
parse
(
request_context
.
request
.
url
)
...
...
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