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

45 lines
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
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
2021-06-08 01:23:25 +05:30
Gitlab::SnippetSearchResults.prepend_mod_with('Gitlab::SnippetSearchResults')