Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,681 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend, search

Hướng nghiên cứu

Bắt đầu trong packages/web/src/features/search/zoektSearcher.ts tại createReposMapForChunk, sau đó đọc phần thiết lập hiện có trong zoektSearcher.test.ts. Tái hiện trường hợp có 100 tệp dùng chung một repository_id và đếm số lần gọi mocked prisma.repo.findUnique. Được xem là hoàn tất khi chỉ có một lần tra cứu cho mỗi repository duy nhất trong một chunk, đồng thời vẫn giữ nguyên hành vi cache streaming hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug triage needed
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.

Ngôn ngữ chính
TypeScript
Star
3.9k
Fork
374
Merge trung bình
21 giờ 18 phút
Pull request đã merge (30 ngày)
39

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sourcebot-dev/sourcebot

Tất cả issue của sourcebot-dev/sourcebot

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.