perf(github): skip the files fetch for already-hydrated merged PRs (#1941) - #1985
Conversation
…1941) The recent-merged backfill re-fetched GET /pulls/{n}/files for every merged PR on every sync (an N+1). A merged PR is immutable, so its changed-file list never changes once stored. Build the set of already-hydrated PRs (one listRecentMergedPullRequests read per batch) and skip the per-PR files fetch for them, re-upserting only cheap metadata (the upsert preserves stored files on an empty list). DRYs the two duplicate loops into hydrateMergedPullRequestFiles.
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-07-01 05:14:03 UTC
⏸️ Suggested Action - Manual Review
Review summary Nits — 6 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 #1985 +/- ##
=======================================
Coverage 95.61% 95.62%
=======================================
Files 218 218
Lines 24306 24308 +2
Branches 8817 8818 +1
=======================================
+ Hits 23241 23244 +3
Misses 436 436
+ Partials 629 628 -1
🚀 New features to boost your workflow:
|
Summary
The recent-merged backfill segment (and the monolithic path) fetched
GET /pulls/{n}/filesfor every merged PR on every sync — an N+1 REST fan-out. But a merged PR is immutable: its changed-file list never changes once stored, so re-fetching it every 6-hour full sync is pure waste.This skips the per-PR
/filesfetch for any merged PR already hydrated: onelistRecentMergedPullRequestsread per batch builds the set of PRs that already have stored files, and those PRs get only a cheap metadata re-upsert (the upsert already preserves stored files when passed an empty list —repositories.ts:3144). Both identical N+1 sites now go through a sharedhydrateMergedPullRequestFileshelper.Advances #1941 (rec #9 from the #1936 audit).
Scope
CONTRIBUTING.md; nosite//CNAME.Validation
git diff --checknpm run typechecknpm run test:coverage— added a regression test that pre-stores a merged PR with files, runs the recent-merged segment, and asserts zero/pulls/{n}/filesfetches while the metadata is still refreshed and the stored files preserved (it fails without the skip). The not-already-stored (fetch) branch stays covered by the existing "hydrates merged PR changed files" test; the changed region is 100% covered (statements + branches).npm run test:ci· all 134 backfill tests pass (the refactor into the shared helper is behavior-preserving)npm audit --audit-level=moderateIf any required check was skipped, explain why:
Safety
Notes
/filesfetch is skipped; the merged PR's metadata (title/labels/merged_at) is still re-upserted each pass, and skipping only happens when files are already stored (a first-time or files-less record still fetches). Merged PRs are terminal, so their file list cannot change after storage..catch(() => [])onfetchPullRequestFiles(it never throws —githubPaginatedListcatches per-page and returns[]/undefined), which the original inline sites carried.