Commit 8216e0be authored by Mark Chao's avatar Mark Chao

Remove unused `FoundBlob` wrapping on view and API

Project batch loading is done in search layer.
parent 0130f678
......@@ -86,19 +86,6 @@ module SearchHelper
}).html_safe
end
def find_project_for_result_blob(projects, result)
@project
end
# Used in EE
def blob_projects(results)
nil
end
def parse_search_result(result)
result
end
# Overriden in EE
def search_blob_title(project, path)
path
......
......@@ -32,8 +32,7 @@
.term
= render 'shared/projects/list', projects: @search_objects, pipeline_status: false
- else
- locals = { projects: blob_projects(@search_objects) } if %w[blobs wiki_blobs].include?(@scope)
= render partial: "search/results/#{@scope.singularize}", collection: @search_objects, locals: locals
= render partial: "search/results/#{@scope.singularize}", collection: @search_objects
- if @scope != 'projects'
= paginate_collection(@search_objects)
- project = find_project_for_result_blob(projects, blob)
- project = blob.project
- return unless project
- blob = parse_search_result(blob)
- blob_link = project_blob_path(project, tree_join(blob.ref, blob.path))
= render partial: 'search/results/blob_data', locals: { blob: blob, project: project, path: blob.path, blob_link: blob_link }
- project = find_project_for_result_blob(projects, wiki_blob)
- wiki_blob = parse_search_result(wiki_blob)
- project = wiki_blob.project
- wiki_blob_link = project_wiki_path(project, wiki_blob.basename)
= render partial: 'search/results/blob_data', locals: { blob: wiki_blob, project: project, path: wiki_blob.path, blob_link: wiki_blob_link }
......@@ -13,29 +13,6 @@ module EE
options
end
override :find_project_for_result_blob
def find_project_for_result_blob(projects, result)
return super if result.is_a?(::Gitlab::Search::FoundBlob)
super || projects&.find { |project| project.id == blob_project_id(result) }
end
override :blob_projects
def blob_projects(results)
return super if results.first.is_a?(::Gitlab::Search::FoundBlob)
project_ids = results.map(&method(:blob_project_id))
::ProjectsFinder.new(current_user: current_user, project_ids_relation: project_ids).execute
end
override :parse_search_result
def parse_search_result(result)
return super if result.is_a?(::Gitlab::Search::FoundBlob)
::Gitlab::Elastic::SearchResults.parse_search_result(result)
end
override :search_blob_title
def search_blob_title(project, path)
if @project
......@@ -88,10 +65,6 @@ module EE
context.feature_available?(:multiple_issue_assignees))
end
def blob_project_id(blob_result)
blob_result.dig('_source', 'join_field', 'parent')&.split('_')&.last.to_i
end
def gitlab_com_snippet_db_search?
@current_user &&
@show_snippets &&
......
......@@ -21,17 +21,6 @@ module EE
def use_elasticsearch?(resource)
::Gitlab::CurrentSettings.search_using_elasticsearch?(scope: resource)
end
override :process_results
def process_results(results)
return [] if results.empty?
if results.any? { |result| result.is_a?(::Elasticsearch::Model::Response::Result) && result.respond_to?(:blob) }
return paginate(results).map { |blob| ::Gitlab::Elastic::SearchResults.parse_search_result(blob) }
end
super
end
end
end
end
......
......@@ -51,67 +51,6 @@ describe SearchHelper do
end
end
describe '#parse_search_result with elastic enabled', :elastic do
let(:user) { create(:user) }
before do
allow(self).to receive(:current_user).and_return(user)
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end
it "returns parsed result", :sidekiq_might_not_need_inline do
project = create :project, :repository
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
result = project.repository.elastic_search(
'def popen',
type: :blob,
options: { highlight: true }
)[:blobs][:results][0]
parsed_result = helper.parse_search_result(result)
expect(parsed_result.ref). to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0')
expect(parsed_result.path).to eq('files/ruby/popen.rb')
expect(parsed_result.startline).to eq(2)
expect(parsed_result.data).to include("Popen")
end
end
describe '#blob_projects', :elastic do
let(:user) { create(:user) }
before do
allow(self).to receive(:current_user).and_return(user)
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end
def es_blob_search
Repository.elastic_search(
'def popen',
type: :blob,
options: { highlight: true }
)[:blobs][:results]
end
it 'returns all projects in the result page without causing an N+1', :sidekiq_might_not_need_inline do
control_count = ActiveRecord::QueryRecorder.new { blob_projects(es_blob_search) }.count
projects = create_list :project, 3, :repository, :public
projects.each { |project| project.repository.index_commits_and_blobs }
Gitlab::Elastic::Helper.refresh_index
# So we can access it outside the following block
result_projects = nil
expect { result_projects = blob_projects(es_blob_search) }.not_to exceed_query_limit(control_count)
expect(result_projects).to match_array(projects)
end
end
describe '#search_entries_info_template' do
let(:com_value) { true }
let(:flag_enabled) { true }
......
......@@ -32,10 +32,6 @@ module API
results = SearchService.new(current_user, search_params).search_objects
process_results(results)
end
def process_results(results)
paginate(results)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment