Describe the bug
When search returns multiple files from the same repository, createReposMapForChunk performs a separate Prisma repository lookup for each file.
The repository cache is checked inside concurrent Promise.all callbacks, but it is only populated after the database query resolves. Because of this, files from the same uncached repository all miss the cache and start duplicate lookups.
For example, I tested 100 search results from the same repository and observed 100 prisma.repo.findUnique calls instead of 1.
I would expect repository metadata to be fetched once per unique repository and reused for the other results.
This adds unnecessary database work to the search path, especially when many results come from the same repository.
To reproduce
Using the existing zoektSearcher.test.ts setup:
Return 100 files with the same repository_id.
Mock prisma.repo.findUnique and count the calls.
Run zoektSearch.
findUnique is called 100 times, even though all files belong to one repository.
I also tested two repositories:
100 files from 1 repository → 100 lookups
100 files split across 2 repositories → 100 lookups
For streaming search, the cache works across completed chunks. A second chunk containing files from an already cached repository makes 0 additional lookups. The duplicate lookups happen within the same chunk.
Sourcebot deployment information
Sourcebot version: Local development build from current main
Additional information
Relevant code:
packages/web/src/features/search/zoektSearcher.ts
Function:
createReposMapForChunk
The same search path is also used by Ask Sourcebot tools such as grep and glob.
I haven't measured the production latency impact, so the confirmed issue here is the redundant database work rather than a specific search latency regression.
Describe the bug
When search returns multiple files from the same repository, createReposMapForChunk performs a separate Prisma repository lookup for each file.
The repository cache is checked inside concurrent Promise.all callbacks, but it is only populated after the database query resolves. Because of this, files from the same uncached repository all miss the cache and start duplicate lookups.
For example, I tested 100 search results from the same repository and observed 100 prisma.repo.findUnique calls instead of 1.
I would expect repository metadata to be fetched once per unique repository and reused for the other results.
This adds unnecessary database work to the search path, especially when many results come from the same repository.
To reproduce
Using the existing zoektSearcher.test.ts setup:
Return 100 files with the same repository_id.
Mock prisma.repo.findUnique and count the calls.
Run zoektSearch.
findUnique is called 100 times, even though all files belong to one repository.
I also tested two repositories:
100 files from 1 repository → 100 lookups
100 files split across 2 repositories → 100 lookups
For streaming search, the cache works across completed chunks. A second chunk containing files from an already cached repository makes 0 additional lookups. The duplicate lookups happen within the same chunk.
Sourcebot deployment information
Sourcebot version: Local development build from current main
Additional information
Relevant code:
packages/web/src/features/search/zoektSearcher.tsFunction:
createReposMapForChunkThe same search path is also used by Ask Sourcebot tools such as grep and glob.
I haven't measured the production latency impact, so the confirmed issue here is the redundant database work rather than a specific search latency regression.