fix(selfhost): bulk-load repo-doc refresh attempt markers in the sweep fan-out - #3219
Conversation
…p fan-out fanOutRepoDocRefreshSweepJobs called getLastRepoDocRefreshAttemptedAt once per installed repo, an N+1 query pattern flagged in review on PR #3202 after it merged (the finding was advisory and did not block the owner-PR auto-merge, so it landed as follow-up work). Adds listLatestSignalSnapshotsForTargets, a bulk latest-per-target-key query, and a getLastRepoDocRefreshAttemptedAtBulk wrapper so the daily sweep does one round trip across every candidate repo instead of scaling linearly with the installed-repo count.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-04 20:40:47 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 4 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3219 +/- ##
=======================================
Coverage 94.75% 94.75%
=======================================
Files 272 272
Lines 29828 29838 +10
Branches 10873 10874 +1
=======================================
+ Hits 28264 28274 +10
Misses 918 918
Partials 646 646
🚀 New features to boost your workflow:
|
Summary
Follow-up to #3202 (merged): the Gittensory review bot flagged an N+1 database pattern in
fanOutRepoDocRefreshSweepJobs(src/queue/processors.ts) -- it calledgetLastRepoDocRefreshAttemptedAtonce per installed repo inside the fan-out loop, so the daily repo-doc refresh sweep's DB round trips scaled linearly with the installed-repo count. The finding was advisory and did not block #3202's auto-merge (CI was green and mergeable-clean), so it lands here as a targeted follow-up rather than blocking that PR further.What changed
listLatestSignalSnapshotsForTargets(src/db/repositories.ts): a bulk variant oflistSignalSnapshotsthat resolves the LATEST snapshot per target key across a list of keys in one query (window-functionrow_number() OVER (PARTITION BY target_key ...), same pattern already used by the existinglistLatestSignalSnapshotsByTarget).getLastRepoDocRefreshAttemptedAtBulk(src/github/repo-doc-refresh-runner.ts): thin wrapper that keeps therepo-doc-refresh-attemptsignal-type constant encapsulated in this module, same as the existing single-repogetLastRepoDocRefreshAttemptedAt.fanOutRepoDocRefreshSweepJobsnow filters to enabled repos first, then does ONE bulk lookup for their attempt markers, instead of one query per repo.Why
The sweep runs once daily across every repo with
repoDocGeneration.enabled. A per-repo query here doesn't show up on a small local install, but on a large self-host fleet it turns one cron tick into N sequential DB calls.Validation
npm run typechecknpx vitest run test/unit/data-spine.test.ts test/unit/repo-doc-refresh-runner.test.ts test/unit/repo-doc-refresh-sweep.test.ts test/unit/mcp-refresh-repo-docs.test.ts test/unit/focus-manifest.test.ts test/unit/index.test.ts-- 298/298 passingnpm run test:changed(diff-aware full sweep againstorigin/main) -- 5500/5507 passing (7 pre-existing skips, 0 failures)coverage/lcov.infoBRDA parsingrepo-doc-refresh-sweep.test.tssuite passing unchangedScope
site/,CNAME, or**/lovable/**Safety