fix(web): deduplicate repository lookups in search results

Closed
DI
2mo ago
+184-32

Fixes #1681

Batch uncached repository IDs into one scoped Prisma query per chunk and cache missing IDs/names for the request. Preserve legacy lookups and file order; tests cover mixed identifiers and streamed metadata mappings.

Validation: application tests, lint, Docker builds, Prisma migration gate, and regression checks passed.


[!NOTE]
Low Risk
Search-path performance fix with behavior preserved (file order, legacy name lookups, omitting unknown repos); risk is limited to repository metadata resolution logic, now covered by expanded tests.

Overview
Fixes redundant Prisma calls when enriching Zoekt file matches with repository metadata.

createReposMapForChunk now collects unique repository identifiers per chunk, batches numeric IDs into a single findMany, and records missing IDs/names in the per-request cache (Repo | null) so later files and streamed chunks do not re-query. Legacy shards without repository_id still resolve via one findFirst per distinct name; numeric IDs and name "1" stay separate.

Adds changelog entry and regression tests for unary/streaming search (batching, missing repos, cache scope per stream, mixed ID/name shards).

Reviewed by Cursor Bugbot for commit 0f2600db907f634d9212e90a542f552bd8e9e5c2. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes #1681 so search results with many files from the same repository no longer trigger a database lookup per file.

Deduplicates repository identifiers before resolving repository metadata in zoektSearcher.ts, so 100 files from one repository make one lookup and 100 files across two repositories make two. Legacy name-based lookups, missing-repository handling, result order, and the existing metadata cache across streamed chunks are preserved. Adds a changelog entry.

Tests

  • Adds regression coverage for repository ID deduplication, name-based lookups, missing repositories, and streaming chunks reusing cached metadata.

Summary by CodeRabbit

  • Bug Fixes
    • Reduced repeated repository metadata lookups when processing search results, including across streamed result batches.
    • Improved search handling for missing repository information: files without a matching repository are omitted, and repeated checks for missing repositories are avoided.
    • Search now handles numeric repository IDs and legacy repository names separately, while grouping numeric ID lookups to reduce redundant queries.