diff options
Diffstat (limited to 'lib/gitlab/search_results.rb')
-rw-r--r-- | lib/gitlab/search_results.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 0473fa89a0d..c35ee62163a 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -4,8 +4,10 @@ module Gitlab class SearchResults COUNT_LIMIT = 100 COUNT_LIMIT_MESSAGE = "#{COUNT_LIMIT - 1}+" + DEFAULT_PAGE = 1 + DEFAULT_PER_PAGE = 20 - attr_reader :current_user, :query, :per_page + attr_reader :current_user, :query # Limit search results by passed projects # It allows us to search only for projects user has access to @@ -17,15 +19,14 @@ module Gitlab # query attr_reader :default_project_filter - def initialize(current_user, limit_projects, query, default_project_filter: false, per_page: 20) + def initialize(current_user, limit_projects, query, default_project_filter: false) @current_user = current_user @limit_projects = limit_projects || Project.all @query = query @default_project_filter = default_project_filter - @per_page = per_page end - def objects(scope, page = nil, without_count = true) + def objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, without_count: true) collection = case scope when 'projects' projects @@ -39,7 +40,9 @@ module Gitlab users else Kaminari.paginate_array([]) - end.page(page).per(per_page) + end + + collection = collection.page(page).per(per_page) without_count ? collection.without_count : collection end |