perf(selfhost): skip reporting-exporter's rebuild when the source is unchanged - #3935
Conversation
…unchanged Every 30s cycle rebuilt the entire Grafana reporting SQLite mirror from scratch, regardless of whether the source data had actually changed -- measured at 91GB of cumulative block I/O in 37 hours on a real self-host instance, growing without bound as ai_usage_events (an append-only log of every AI call) accumulates. A live review pipeline is bursty: most cycles change nothing since the last export. Add a cheap COUNT+MAX fingerprint per source table (both the SQLite and Postgres source paths) and skip the full rebuild when it matches the last run's and a last-good output DB already exists. Fails open: any error computing the fingerprint falls through to the existing full-rebuild path unchanged, so this is purely an optimization, never a new failure mode. Closes #3895
|
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 #3935 +/- ##
=======================================
Coverage 93.58% 93.58%
=======================================
Files 358 358
Lines 34342 34342
Branches 12570 12570
=======================================
Hits 32138 32138
Misses 1580 1580
Partials 624 624 🚀 New features to boost your workflow:
|
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-07 07:25:37 UTC
✅ Suggested Action - Approve/Merge
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.
|
Summary
scripts/export-grafana-reporting-db.sh(run every 30s by default viareporting-exporterindocker-compose.yml) rebuilt the ENTIRE Grafana reporting SQLite mirror from scratch every cycle — full re-export + re-import ofpull_requests/review_audit-derivedreview_targetsand the fullai_usage_eventstable, regardless of whether anything had actually changed.ai_usage_eventsis an append-only log of every AI call, so this cost only grows as review volume grows — a real, currently-active scalability ceiling.COUNT(*) || MAX(<timestamp column>)fingerprint per source table (pull_requests,review_audit,review_targets,ai_usage_events), computed for BOTH the SQLite-source and Postgres-source paths. When the fingerprint matches the last run's AND a last-good output DB already exists, the entire rebuild is skipped.0(skipped) on the second occurrence instead of the previousexit 1("preserving last good"). Same last-good snapshot is preserved either way — only the exit code/log-noise differs, and it stops the container'swhile trueloop from logging[reporting] export failedevery 30s forever on a fresh, not-yet-migrated instance.Found via a fresh performance/scalability/accuracy hardening audit of the self-host ORB stack (this is the finding with the real measured production evidence). Tracked under #1667.
Scope
scripts/export-grafana-reporting-db.sh— fingerprint fast-path for both source pathstest/unit/selfhost-grafana-reporting.test.ts— 3 new tests (SQLite skip, SQLite redo-on-change, Postgres skip); all 14 pre-existing tests pass unmodifiedValidation
sh -n scripts/export-grafana-reporting-db.sh(syntax check)npm run typechecknpx vitest run test/unit/selfhost-grafana-reporting.test.ts— 17/17 passing (14 pre-existing + 3 new)git diff --checkcleanSafety
scripts/**andtest/**— no Codecov patch-coverage obligation, but the full existing correctness test suite (gate-decision precedence, IPv6 host parsing, column-fallback compat, BusyBoxmktempcompat, fail-closed-on-Postgres-error) passes untouched, proving the rebuild path itself is byte-identical when it does run.Closes #3895