Commit ccbd7f31 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '118669-blob-preload' into 'master'

Prevent Gitaly N+1 queries in blob search

See merge request gitlab-org/gitlab!21996
parents bf0e9520 83e79096
---
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