Commit 83e79096 authored by Mark Chao's avatar Mark Chao

Avoids N+1 query when path fileter is triggered

Currently gitaly can return large number of filename search results,
but since binary_path is not set, our ruby filter would acquire it by
fetching blob data from gitaly, causing performance issue.

By setting binary_path, the fetching can be avoided.
parent 62052283
---
title: Fix slow query on blob search when doing path filtering
merge_request: 21996
author:
type: performance
......@@ -37,7 +37,7 @@ module Gitlab
def find_by_path(query)
search_paths(query).map do |path|
Gitlab::Search::FoundBlob.new(blob_path: path, project: project, ref: ref, repository: repository)
Gitlab::Search::FoundBlob.new(blob_path: path, path: path, project: project, ref: ref, repository: repository)
end
end
......
......@@ -30,5 +30,11 @@ describe Gitlab::FileFinder do
expect(results.count).to eq(1)
end
it 'does not cause N+1 query' do
expect(Gitlab::GitalyClient).to receive(:call).at_most(10).times.and_call_original
subject.find(': filename:wm.svg')
end
end
end
......@@ -86,8 +86,7 @@ describe Gitlab::ProjectSearchResults do
it "loads all blobs for path matches in single batch" do
expect(Gitlab::Git::Blob).to receive(:batch).once.and_call_original
expected = project.repository.search_files_by_name(query, 'master')
expect(results.map(&:path)).to include(*expected)
results.map(&:data)
end
it 'finds by content' do
......
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