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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
1b2400b5
Commit
1b2400b5
authored
Feb 06, 2018
by
Jarka Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return only limited pagination headers for search API endpoints
parent
73819445
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
12 deletions
+26
-12
app/services/search_service.rb
app/services/search_service.rb
+1
-1
lib/api/helpers/pagination.rb
lib/api/helpers/pagination.rb
+13
-4
lib/api/search.rb
lib/api/search.rb
+1
-2
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+2
-2
lib/gitlab/snippet_search_results.rb
lib/gitlab/snippet_search_results.rb
+2
-2
spec/requests/api/search_spec.rb
spec/requests/api/search_spec.rb
+1
-1
spec/support/matchers/pagination_matcher.rb
spec/support/matchers/pagination_matcher.rb
+6
-0
No files found.
app/services/search_service.rb
View file @
1b2400b5
...
...
@@ -43,7 +43,7 @@ class SearchService
end
def
search_objects
@search_objects
||=
search_results
.
objects
(
scope
,
params
[
:page
]
,
params
[
:without_counts
]
)
@search_objects
||=
search_results
.
objects
(
scope
,
params
[
:page
])
end
private
...
...
lib/api/helpers/pagination.rb
View file @
1b2400b5
...
...
@@ -12,13 +12,16 @@ module API
private
def
add_pagination_headers
(
paginated_data
)
header
'X-Total'
,
paginated_data
.
total_count
.
to_s
header
'X-Total-Pages'
,
total_pages
(
paginated_data
).
to_s
header
'X-Per-Page'
,
paginated_data
.
limit_value
.
to_s
header
'X-Page'
,
paginated_data
.
current_page
.
to_s
header
'X-Next-Page'
,
paginated_data
.
next_page
.
to_s
header
'X-Prev-Page'
,
paginated_data
.
prev_page
.
to_s
header
'Link'
,
pagination_links
(
paginated_data
)
return
if
data_without_counts?
(
paginated_data
)
header
'X-Total'
,
paginated_data
.
total_count
.
to_s
header
'X-Total-Pages'
,
total_pages
(
paginated_data
).
to_s
end
def
pagination_links
(
paginated_data
)
...
...
@@ -37,8 +40,10 @@ module API
request_params
[
:page
]
=
1
links
<<
%(<#{request_url}?#{request_params.to_query}>; rel="first")
request_params
[
:page
]
=
total_pages
(
paginated_data
)
links
<<
%(<#{request_url}?#{request_params.to_query}>; rel="last")
unless
data_without_counts?
(
paginated_data
)
request_params
[
:page
]
=
total_pages
(
paginated_data
)
links
<<
%(<#{request_url}?#{request_params.to_query}>; rel="last")
end
links
.
join
(
', '
)
end
...
...
@@ -55,6 +60,10 @@ module API
relation
end
def
data_without_counts?
(
paginated_data
)
paginated_data
.
is_a?
(
Kaminari
::
PaginatableWithoutCount
)
end
end
end
end
lib/api/search.rb
View file @
1b2400b5
...
...
@@ -24,8 +24,7 @@ module API
search:
params
[
:search
],
snippets:
snippets?
,
page:
params
[
:page
],
per_page:
params
[
:per_page
],
without_counts:
false
per_page:
params
[
:per_page
]
}.
merge
(
additional_params
)
results
=
SearchService
.
new
(
current_user
,
search_params
).
search_objects
...
...
lib/gitlab/project_search_results.rb
View file @
1b2400b5
...
...
@@ -10,7 +10,7 @@ module Gitlab
@per_page
=
per_page
end
def
objects
(
scope
,
page
=
nil
,
without_counts
=
true
)
def
objects
(
scope
,
page
=
nil
)
case
scope
when
'notes'
notes
.
page
(
page
).
per
(
per_page
)
...
...
@@ -21,7 +21,7 @@ module Gitlab
when
'commits'
Kaminari
.
paginate_array
(
commits
).
page
(
page
).
per
(
per_page
)
else
super
(
scope
,
page
,
without_counts
)
super
(
scope
,
page
,
false
)
end
end
...
...
lib/gitlab/snippet_search_results.rb
View file @
1b2400b5
...
...
@@ -9,14 +9,14 @@ module Gitlab
@query
=
query
end
def
objects
(
scope
,
page
=
nil
,
without_counts
=
true
)
def
objects
(
scope
,
page
=
nil
)
case
scope
when
'snippet_titles'
snippet_titles
.
page
(
page
).
per
(
per_page
)
when
'snippet_blobs'
snippet_blobs
.
page
(
page
).
per
(
per_page
)
else
super
(
scope
,
nil
,
without_counts
)
super
(
scope
,
nil
,
false
)
end
end
...
...
spec/requests/api/search_spec.rb
View file @
1b2400b5
...
...
@@ -9,7 +9,7 @@ describe API::Search do
shared_examples
'response is correct'
do
|
schema
:,
size:
1
|
it
{
expect
(
response
).
to
have_gitlab_http_status
(
200
)
}
it
{
expect
(
response
).
to
match_response_schema
(
schema
)
}
it
{
expect
(
response
).
to
include_pagination_headers
}
it
{
expect
(
response
).
to
include_
limited_
pagination_headers
}
it
{
expect
(
json_response
.
size
).
to
eq
(
size
)
}
end
...
...
spec/support/matchers/pagination_matcher.rb
View file @
1b2400b5
...
...
@@ -3,3 +3,9 @@ RSpec::Matchers.define :include_pagination_headers do |expected|
expect
(
actual
.
headers
).
to
include
(
'X-Total'
,
'X-Total-Pages'
,
'X-Per-Page'
,
'X-Page'
,
'X-Next-Page'
,
'X-Prev-Page'
,
'Link'
)
end
end
RSpec
::
Matchers
.
define
:include_limited_pagination_headers
do
|
expected
|
match
do
|
actual
|
expect
(
actual
.
headers
).
to
include
(
'X-Per-Page'
,
'X-Page'
,
'X-Next-Page'
,
'X-Prev-Page'
,
'Link'
)
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