diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-02-06 17:53:42 +0100 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-02-06 17:58:18 +0100 |
commit | 1b2400b529628da08e406e2391ef37c0b05f889e (patch) | |
tree | d2c0c3f355d7a60a9de2c7370b3b19a77b8e50a6 /lib | |
parent | 7381944565701f2a8db5d58d5bc3c7e52e7f60bf (diff) | |
download | gitlab-ce-1b2400b529628da08e406e2391ef37c0b05f889e.tar.gz |
Return only limited pagination headers for search API endpoints
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers/pagination.rb | 17 | ||||
-rw-r--r-- | lib/api/search.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/project_search_results.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/snippet_search_results.rb | 4 |
4 files changed, 18 insertions, 10 deletions
diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb index bb70370ba77..09805049169 100644 --- a/lib/api/helpers/pagination.rb +++ b/lib/api/helpers/pagination.rb @@ -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 diff --git a/lib/api/search.rb b/lib/api/search.rb index 31121b3ee2d..3912c66657e 100644 --- a/lib/api/search.rb +++ b/lib/api/search.rb @@ -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 diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 0846fdc4de3..9e2fa07a205 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -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 diff --git a/lib/gitlab/snippet_search_results.rb b/lib/gitlab/snippet_search_results.rb index 98c43475303..4f86b3e8f73 100644 --- a/lib/gitlab/snippet_search_results.rb +++ b/lib/gitlab/snippet_search_results.rb @@ -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 |