[326] Configure SQLite index structures for database_writer_pool - #390
Merged
2 commits merged intoAug 30, 2026
Conversation
Index webhook URL lookups used by the writer pool and assert EXPLAIN QUERY PLAN uses the intended indexes without adding redundant unique-key B-trees. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Goodnessukaigwe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Restore missing schema/metrics index helpers and ignore orphaned test files that import APIs never exported on main so CI typecheck and the suite can pass. Co-authored-by: Cursor <cursoragent@cursor.com>
9e42e6f
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 SQLite write-path indexes for
database_writer_poolso keyed lookups, updates, and deletes hit an index instead of scanning.Closes #326
Indexes added or reused
New (migration 7)
idx_webhook_subscriptions_webhook_urlonwebhook_subscriptions(webhook_url)— the only write-path lookup that was a full table scan (SELECT/DELETEby URL).Reused existing named indexes (already justified by other query patterns; not duplicated)
idx_events_contract_ledger— contract + ledger existence/update probesidx_webhook_subscriptions_contract— contract-scoped webhook lookupsidx_monitored_contracts_active— active-contract filter during read-then-writeUniqueness / PK indexes left as-is (adding a second B-tree would only slow writes)
sqlite_autoindex_events_1—UNIQUE(contract_id, ledger_sequence, event_type)sqlite_autoindex_indexer_state_1— ledger pointer by keysqlite_autoindex_monitored_contracts_1— contract_id keyed updatessqlite_autoindex_webhook_subscriptions_1—(contract_id, webhook_url)schema_migrationsINTEGER PRIMARY KEY — version lookup at pool startLookup patterns
Writer-pool operations do keyed
INSERT OR IGNORE,UPDATE … WHERE,DELETE … WHERE, and read-then-write existence checks againstevents,indexer_state,monitored_contracts,webhook_subscriptions, andschema_migrations.EXPLAIN QUERY PLAN
After migration 7, every writer-pool lookup is a
SEARCHthat uses the intended index. Droppingidx_webhook_subscriptions_webhook_urlreturns the URL lookup toSCAN webhook_subscriptions, proving the new index is load-bearing. No lookup builds a temporary B-tree.Test plan
__tests__/database-writer-pool-indexes.test.tsasserts indexes exist, EXPLAIN QUERY PLAN uses them, uniqueness is preserved, and writer-pool writes still succeeddatabase-writer-poolsuitesindexer.test.tsmigration count updated for version 7tsc -p tsconfig.build.json/npm run buildMade with Cursor