Repository navigation
perf(database): add status + createdAt composite indexes - #477
Open
francescoricc1 wants to merge 1 commit into
Open
francescoricc1 wants to merge 1 commit into
francescoricc1 wants to merge 1 commit into
Conversation
Status-filtered listings and agent spend windows currently combine single-column status/createdAt indexes or sort every match, which shows up as high query latency and CPU on the transactions ledger. Add composite (organizationId|agentId, status, createdAt) indexes for transactions, agents, wallets and users, each in its own concurrent migration so writes stay unblocked. Ship idempotent down.sql rollbacks and a structural test that keeps the SQL, schema declarations and rollbacks in sync. Closes ASTROIDX556#293 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the missing composite
(scope, status, createdAt)indexes behind the slow status-filtered record queries:transactions (organizationId, status, createdAt)— status-filtered listing and dashboard aggregatestransactions (agentId, status, createdAt)— daily/weekly/monthly and rolling spend windowsagents (organizationId, status, createdAt)— status-filtered agent listingwallets (organizationId, status, createdAt)— status-filtered wallet listingusers (organizationId, status, createdAt)— active-member filters and broadcast fan-outEach index ships in its own
CREATE INDEX CONCURRENTLYmigration so writes are not blocked, with a matching idempotentdown.sqlrollback (DROP INDEX CONCURRENTLY IF EXISTS).schema.prismadeclares every index so there is no drift, andsrc/database/index-migrations.spec.tskeeps the up/down SQL in sync.Verification
prisma validateandtsc --noEmitpassscripts/verify-migrations.shreplays the full history on a fresh Postgres 16 shadow database with no driftEXPLAIN (ANALYZE, BUFFERS)against 200k transactions and 20k agents/wallets/users shows index scans on each new index (no sequential scans); rollback removes all five and re-apply restores themCloses #293
closes #294
closes #298
closes #301