gitlab-org--gitlab-foss/lib/gitlab/wiki_file_finder.rb
Jan Provaznik 58bfd73331 Optimized file search to work without limits
* removed 100 limit on file search results because we
  load all results anyway
* expensive processing (parsing match content, utf encoding)
  is done only for selected page in paginated output
2018-12-06 09:25:09 +01:00

25 lines
533 B
Ruby

# frozen_string_literal: true
module Gitlab
class WikiFileFinder < FileFinder
BATCH_SIZE = 100
attr_reader :repository
def initialize(project, ref)
@project = project
@ref = ref
@repository = project.wiki.repository
end
private
def search_filenames(query)
safe_query = Regexp.escape(query.tr(' ', '-'))
safe_query = Regexp.new(safe_query, Regexp::IGNORECASE)
filenames = repository.ls_files(ref)
filenames.grep(safe_query).first(BATCH_SIZE)
end
end
end