Skip to content

perf(db): add covering index on alerts_fired(resolved, fired_at DESC) - #538

Merged
AbdulmalikAlayande merged 1 commit into
TegoLabs:mainfrom
marvelousjeremiah24:feat/index-alerts-fired-resolved-fired-at
Aug 1, 2026
Merged

AbdulmalikAlayande merged 1 commit into
TegoLabs:mainfrom
marvelousjeremiah24:feat/index-alerts-fired-resolved-fired-at

Conversation

@marvelousjeremiah24

Copy link
Copy Markdown
Contributor

getAlertHistory and related queries filter/sort on resolved and fired_at but had no covering index. Add idx_alerts_fired_resolved_fired_at to eliminate the full-table scan + temporary B-TREE sort on larger deployments.

CREATE INDEX IF NOT EXISTS is idempotent — re-runs safely on every getDatabase() call for existing installs, no live-migration code needed.

Tests: add 3 tests to tests/db/database.test.ts verifying

  • the index exists on a freshly created database (sqlite_master check)
  • the index covers the correct columns (resolved, fired_at)
  • EXPLAIN QUERY PLAN for getAlertHistory's query is valid and documented

What does this PR do?

Why?

Does this touch secret-key handling or transaction submission?

  • Yes — see notes above
  • No

Checklist

getAlertHistory and related queries filter/sort on resolved and fired_at
but had no covering index. Add idx_alerts_fired_resolved_fired_at to
eliminate the full-table scan + temporary B-TREE sort on larger deployments.

CREATE INDEX IF NOT EXISTS is idempotent — re-runs safely on every
getDatabase() call for existing installs, no live-migration code needed.

Tests: add 3 tests to tests/db/database.test.ts verifying
- the index exists on a freshly created database (sqlite_master check)
- the index covers the correct columns (resolved, fired_at)
- EXPLAIN QUERY PLAN for getAlertHistory's query is valid and documented
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@marvelousjeremiah24, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 879d476b-d177-401b-8ce8-dc58d3ad9674

📥 Commits

Reviewing files that changed from the base of the PR and between 35d9237 and 59609d2.

📒 Files selected for processing (2)
  • src/db/schema.sql
  • tests/db/database.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

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

@gitguardian

gitguardian Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Generic High Entropy Secret ded54f4 tests/commands/guard-cli-export-import.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@AbdulmalikAlayande
AbdulmalikAlayande merged commit a39114b into TegoLabs:main Aug 1, 2026
3 of 5 checks passed
@AbdulmalikAlayande

Copy link
Copy Markdown
Collaborator

Merged into main (a39114b) after local verification (tsc, lint, full suite 1202/1202, npm audit, build). Clean, well-scoped PR — nice touch documenting why the EXPLAIN QUERY PLAN test is a soft assertion on an empty test DB rather than a hard one. Thanks!

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.

feat(db): add index on alerts_fired(resolved, fired_at) for faster history queries

2 participants