Skip to content

fix(storage): index triggers_occurrences(trigger_id, date) (EN-1231) - #194

Closed
flemzord wants to merge 1 commit into
mainfrom
fix/trigger-occurrences-index
Closed

fix(storage): index triggers_occurrences(trigger_id, date) (EN-1231)#194
flemzord wants to merge 1 commit into
mainfrom
fix/trigger-occurrences-index

Conversation

@flemzord

Copy link
Copy Markdown
Member

Problem (H12 — HIGH)

Migration 8 dropped the (trigger_id, event_id) primary key in favour of (id), leaving trigger_id unindexed. ListTriggersOccurrences filters WHERE trigger_id = ? ordered by date (internal/triggers/manager.go), and triggers_occurrences gains one row per matched event — so every page request is a sequential scan over an ever-growing table, plus OFFSET.

Fix

Add a migration creating the composite index triggers_occurrences (trigger_id, date):

  • built CONCURRENTLY to avoid blocking writes during deploy (the go-libs migrator runs each migration on a dedicated, non-transactional connection, so CONCURRENTLY is valid here — verified against the migration test harness);
  • IF NOT EXISTS for idempotency.

Test

Verified the full storage.Migrate chain runs cleanly (storage + triggers integration suites).

Severity: HIGH.

Migration 8 dropped the (trigger_id, event_id) primary key in favour of
(id), leaving trigger_id unindexed. ListTriggersOccurrences filters
WHERE trigger_id = ? ordered by date, so every page was a sequential scan
over an ever-growing table.

Add a migration creating the composite index, built CONCURRENTLY (the
migrator runs each migration on a dedicated non-transactional connection)
and IF NOT EXISTS for idempotency.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@flemzord, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3a878bd-c738-425a-937e-0dabdd87659c

📥 Commits

Reviewing files that changed from the base of the PR and between 271bf8d and 52c32be.

📒 Files selected for processing (1)
  • internal/storage/migrations.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/trigger-occurrences-index

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 and usage tips.

@flemzord

flemzord commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Tracked in Jira: EN-1231 (Epic EN-1217).

@flemzord flemzord changed the title fix(storage): index triggers_occurrences(trigger_id, date) fix(storage): index triggers_occurrences(trigger_id, date) (EN-1231) Jun 11, 2026
@flemzord

flemzord commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch.

@flemzord flemzord closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant