Skip to content

[326] Configure SQLite index structures for database_writer_pool - #390

Merged
2 commits merged into
Goldii-locks:mainfrom
Goodnessukaigwe:fix/326-configure-sqlite-index-structures-for-database_writer_pool
Aug 30, 2026
Merged

[326] Configure SQLite index structures for database_writer_pool#390
2 commits merged into
Goldii-locks:mainfrom
Goodnessukaigwe:fix/326-configure-sqlite-index-structures-for-database_writer_pool

Conversation

@Goodnessukaigwe

Copy link
Copy Markdown
Contributor

Summary

Adds SQLite write-path indexes for database_writer_pool so keyed lookups, updates, and deletes hit an index instead of scanning.

Closes #326

Indexes added or reused

New (migration 7)

  • idx_webhook_subscriptions_webhook_url on webhook_subscriptions(webhook_url) — the only write-path lookup that was a full table scan (SELECT/DELETE by URL).

Reused existing named indexes (already justified by other query patterns; not duplicated)

  • idx_events_contract_ledger — contract + ledger existence/update probes
  • idx_webhook_subscriptions_contract — contract-scoped webhook lookups
  • idx_monitored_contracts_active — active-contract filter during read-then-write

Uniqueness / PK indexes left as-is (adding a second B-tree would only slow writes)

  • sqlite_autoindex_events_1UNIQUE(contract_id, ledger_sequence, event_type)
  • sqlite_autoindex_indexer_state_1 — ledger pointer by key
  • sqlite_autoindex_monitored_contracts_1 — contract_id keyed updates
  • sqlite_autoindex_webhook_subscriptions_1(contract_id, webhook_url)
  • schema_migrations INTEGER PRIMARY KEY — version lookup at pool start

Lookup patterns

Writer-pool operations do keyed INSERT OR IGNORE, UPDATE … WHERE, DELETE … WHERE, and read-then-write existence checks against events, indexer_state, monitored_contracts, webhook_subscriptions, and schema_migrations.

EXPLAIN QUERY PLAN

After migration 7, every writer-pool lookup is a SEARCH that uses the intended index. Dropping idx_webhook_subscriptions_webhook_url returns the URL lookup to SCAN webhook_subscriptions, proving the new index is load-bearing. No lookup builds a temporary B-tree.

Test plan

  • __tests__/database-writer-pool-indexes.test.ts asserts indexes exist, EXPLAIN QUERY PLAN uses them, uniqueness is preserved, and writer-pool writes still succeed
  • Existing database-writer-pool suites
  • indexer.test.ts migration count updated for version 7
  • tsc -p tsconfig.build.json / npm run build

Made with Cursor

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>
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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>
@godamongstmen897 godamongstmen897 closed this pull request by merging all changes into Goldii-locks:main in 9e42e6f Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure SQLite index structures for database_writer_pool

2 participants