Skip to content

feat(indexer): configure SQLite index structures for indexer_runner - #359

Merged
3 commits merged into
Goldii-locks:mainfrom
hauwauyahass-byte:fix/issue-250
Aug 30, 2026
Merged

feat(indexer): configure SQLite index structures for indexer_runner#359
3 commits merged into
Goldii-locks:mainfrom
hauwauyahass-byte:fix/issue-250

Conversation

@hauwauyahass-byte

@hauwauyahass-byte hauwauyahass-byte commented Aug 27, 2026

Copy link
Copy Markdown

Closes #250

Summary

Configures SQLite index structures for the indexer_runner execution loop and verifies index utilization with EXPLAIN QUERY PLAN.

The poller (src/indexer/poller.ts) hits a handful of lookup queries every cycle. These were either full table scans (no covering index) or relying on incidental ones. This PR adds deliberate indexes for the hot paths:

  • monitored_contracts (active)idx_monitored_contracts_active backs getActiveContractIds() (WHERE active = 1), the lookup the runner performs on every poll cycle. Added via migration v5.
  • events (created_at)idx_events_created_at backs the MAX(created_at) status aggregation in getIndexerStatusData().
  • sync_ranges (start_ledger, end_ledger)idx_sync_ranges_ledgers backs the range lookup in isLedgerSynced() during historical backfill (created alongside the table, since sync_ranges is defined outside the migration array).

Verification

  • Added __tests__/indexer-indexes.test.ts which seeds representative rows and runs EXPLAIN QUERY PLAN against each runner query, asserting the expected index is referenced, plus functional checks (getActiveContractIds, getIndexerStatusData, isLedgerSynced).
  • indexer.test.ts migration-count assertion updated 4 -> 5 for the new migration.

Local test results

  • jest (new indexer-indexes suite): 4 passed, 0 failed
  • jest full suite: my suites green; the only failing suites are pre-existing upstream failures unrelated to this change (ledger-range-tracker-improvements.test.ts fails to load — imports non-existent DEFAULT_LEDGER_RANGE_FAILURE_THRESHOLD; poller-alerting-diagnostics.test.ts pre-existing) that also fail on the base branch.
  • tsc -p tsconfig.build.json: my changed files type-check; remaining errors are pre-existing in poller.ts (unrelated).

Fixes #250

…-locks#250)

Optimize lookup indexes for the tables the indexer_runner execution loop
accesses and verify index utilization with EXPLAIN QUERY PLAN.

- db.ts: add migration v5 with idx_monitored_contracts_active (backing
  getActiveContractIds WHERE active = 1, the per-cycle poll lookup) and
  idx_events_created_at (backing MAX(created_at) status aggregation).
  Export INDEXER_RUNNER_INDEXES for the EXPLAIN tests.
- duplicate-prevention.ts: create idx_sync_ranges_ledgers on
  (start_ledger, end_ledger) at table creation, backing isLedgerSynced
  range lookups. Export SYNC_RANGES_INDEXES.
- indexer-indexes.test.ts: new suite asserting each plan references the
  expected index via EXPLAIN QUERY PLAN, plus functional checks.
- indexer.test.ts: update expected migration count 4 -> 5.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@hauwauyahass-byte 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

@hauwauyahass-byte

Copy link
Copy Markdown
Author

@Goldii-locks @hauwauyahass-byte Status update for #250: build fails in TypeScript tests: indexer event mock signature and SQLite schema-manager test/API mismatches remain; no code change pushed. Please review the linked CI result and rerun checks where applicable.

@hauwauyahass-byte

Copy link
Copy Markdown
Author

@Goldii-locks @hauwauyahass-byte PR #359 references Fixes #250. Please review/rerun CI.

@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 indexer_runner

3 participants