Skip to content

[bug] Search result hydration performs duplicate repository lookups within the same chunk #1681

Description

@Abhishek-Sonje

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions