debian-mirror-gitlab/lib/gitlab/snippet_search_results.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
module Gitlab
class SnippetSearchResults < SearchResults
2016-04-02 18:10:28 +05:30
include SnippetsHelper
2019-12-21 20:55:43 +05:30
attr_reader :current_user
2015-04-26 12:48:37 +05:30
2019-12-21 20:55:43 +05:30
def initialize(current_user, query)
@current_user = current_user
2015-04-26 12:48:37 +05:30
@query = query
end
2020-06-23 00:09:42 +05:30
def objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, preload_method: nil)
2020-05-24 23:13:21 +05:30
paginated_objects(snippet_titles, page, per_page)
2015-04-26 12:48:37 +05:30
end
2019-10-12 21:52:04 +05:30
def formatted_count(scope)
2020-05-24 23:13:21 +05:30
formatted_limited_count(limited_snippet_titles_count)
2019-10-12 21:52:04 +05:30
end
2019-12-21 20:55:43 +05:30
def limited_snippet_titles_count
@limited_snippet_titles_count ||= limited_count(snippet_titles)
2015-04-26 12:48:37 +05:30
end
private
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2019-12-21 20:55:43 +05:30
def snippets
SnippetsFinder.new(current_user, finder_params)
.execute
.includes(:author)
.reorder(updated_at: :desc)
2015-04-26 12:48:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2015-04-26 12:48:37 +05:30
2019-12-21 20:55:43 +05:30
def snippet_titles
snippets.search(query)
end
2020-05-24 23:13:21 +05:30
def paginated_objects(relation, page, per_page)
2019-12-21 20:55:43 +05:30
relation.page(page).per(per_page)
end
def finder_params
{}
end
2015-04-26 12:48:37 +05:30
end
end
2019-12-21 20:55:43 +05:30
Gitlab::SnippetSearchResults.prepend_if_ee('::EE::Gitlab::SnippetSearchResults')