Gitaly n+1 in /api/:version/projects/:id/(-/)search?scope=blob endpoint
The /api/:version/projects/:id/(-/)search endpoint appears to iterate though each blob in a repository when scope=blob is used in the search.
This leads to mechanical sympathy alerts such as:
There appears to be some evidence in gitlab-com/gl-infra/scalability#64 (comment 261727093) that this is causing latency spikes across the fleet.
Cause
- When user does a blob search with a path filter (e.g.
foo filename:bar), and there are thousands of potential matches - Those thousands of results would return and wrapped as
FoundBlob. - Since
filename:foois present, the ruby side filtering is initiated - The ruby side filtering currently compares search term
barwithFoundBlob#binary_path, which is nil but can be lazy loaded -
FoundBlobtherefore would load blob data from Gitaly, causing N+1 queries.
Edited by Mark Chao
