fix(orb): index orb_relay_pending by created_at so the relay-drain prune stops full-scanning - #7451
fix(orb): index orb_relay_pending by created_at so the relay-drain prune stops full-scanning#7451bitfathers94 wants to merge 1 commit into
Conversation
…une stops full-scanning pruneRelayPending runs on every pull-mode relay-drain (fleet-wide, every 30s) and filters orb_relay_pending by a bare created_at predicate: SELECT ... WHERE created_at < ? ORDER BY created_at, delivery_id LIMIT ? DELETE WHERE created_at < ? Both existing indexes (idx_orb_relay_pending_install, idx_orb_relay_pending_coalesce) lead with installation_id, so neither serves a created_at-only predicate — the SELECT and DELETE full-scan the table and can blow the pull request's AbortSignal.timeout(30_000) budget, surfacing as the recurring TimeoutError in Sentry. Add a (created_at, delivery_id) index: it turns both queries into range scans and lets the SELECT satisfy its ORDER BY (created_at, delivery_id) straight from the index with no temp-B-tree sort. Closes JSONbored#7430
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7451 +/- ##
=======================================
Coverage 91.35% 91.35%
=======================================
Files 716 716
Lines 72990 72990
Branches 21628 21627 -1
=======================================
Hits 66678 66678
Misses 5272 5272
Partials 1040 1040
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-20 11:02:40 UTC
Review summary Nits — 4 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
LoopOver is closing this pull request on the maintainer's behalf (Linked issue #7430 is assigned to the maintainer (@JSONbored) — that work is reserved for the maintainer, so this PR cannot be auto-accepted.). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed. |
Summary
pruneRelayPendingruns on every pull-mode relay-drain (POST /v1/orb/relay/pull, fleet-wide, every 30s) and filtersorb_relay_pendingby a barecreated_atpredicate. Both existing indexes lead withinstallation_id, so neither can serve it — the SELECT and DELETE full-scan the table and can exceed the pull request'sAbortSignal.timeout(30_000)budget, surfacing as the recurringTimeoutErrorin Sentry since 2026-07-15.(created_at, delivery_id)index (idx_orb_relay_pending_created_at) — declared insrc/db/schema.tsand created inmigrations/0167_orb_relay_pending_created_at_index.sql. It turns both the SELECT (WHERE created_at < ? ORDER BY created_at, delivery_id) and the DELETE (WHERE created_at < ?) into index range scans, and lets the SELECT satisfy itsORDER BYfrom the index with no temp-B-tree sort.Closes #7430
Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #7430).Validation
git diff --checknpm run db:migrations:check(contiguous 0001..0167, no new duplicates)npm run db:schema-drift:check(schema.ts matches migrations/)npm run typechecktest/unit/orb-relay-pending-index.test.tsasserts the index exists and that both ofpruneRelayPending's queriesEXPLAIN QUERY PLANas a SEARCH viaidx_orb_relay_pending_created_at(not aSCAN, and with no temp-B-tree sort). It fails before this change (full scan) and passes after.test/integration/orb-relay.test.ts(83 tests) still green.codecov/patch: the only measured diff line is the schema.ts index declaration, executed at module import like its sibling index declarations; the migration and test files are not coverage-measured.Safety
Notes
ORDER BY (created_at, delivery_id)column order so the drain prune needs neither a full scan nor a sort step.