perf(db): optimize recurring query paths - #7014
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryHigh Risk Overview Logs export now pages with a Billing reads ledger totals and daily-refresh consumption from one snapshot via Batching: public workspace listing hydrates a page of details and member counts in one query; custom-block input hydration is concurrency-capped and passes source A migration adds query-shaped indexes (documents, connector sync logs, table views, workflows), drops duplicate unique-key indexes, and lowers Reviewed by Cursor Bugbot for commit 72eb8b6. Configure here. |
Greptile SummaryThe PR optimizes recurring database reads through keyset log-export pagination, bounded execution-data hydration, combined billing aggregation, batched workspace and custom-block reads, and query-matched indexes.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported one-query-per-row amplification is fixed by bounded 100-row keyset pages, 20-way hydration chunks, and deferred next-page reads.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/logs/export/route.ts | Replaces offset pagination with deterministic 100-row keyset reads, bounded hydration, pull-driven row delivery, and cancellation handling. |
| apps/sim/app/api/logs/export/route.test.ts | Covers authorization, cursor precision and ordering, bounded hydration, page-level backpressure, and cancellation. |
| apps/sim/lib/billing/calculations/usage-monitor.ts | Consolidates ledger and daily-refresh calculations while retaining paid-plan clamping and organization-member bounds. |
| apps/sim/lib/billing/credits/daily-refresh.ts | Combines billing-period ledger totals and bounded daily-refresh aggregation into fewer database reads. |
| packages/db/migrations/0303_colorful_gressill.sql | Adds query-shape-matched indexes, removes redundant indexes, and adjusts maintenance settings using deploy-safe concurrent operations. |
| packages/db/schema.ts | Aligns the Drizzle index definitions and table maintenance configuration with the migration. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[CSV consumer pull] --> B[Fetch up to 100 logs by keyset]
B --> C[Hydrate up to 20 execution payloads]
C --> D[Yield CSV rows individually]
D --> E{Page consumed?}
E -- No --> D
E -- Yes, full page --> F[Advance startedAt and id cursor]
F --> B
E -- Yes, partial page --> G[Close stream]
Reviews (5): Last reviewed commit: "fix(logs): guard export stream cancellat..." | Re-trigger Greptile
|
@cursor review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 396884f. Configure here.
396884f to
3ca60d2
Compare
|
@cursor review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 72eb8b6. Configure here.
Summary
These changes preserve existing authorization, filtering, ordering, aggregation, and response contracts. Index changes intentionally balance targeted read improvements against their write and storage cost.
Type of Change
Testing
bun run type-checkbun run lintbun run check:auditsbun run check:migrations origin/stagingChecklist