Skip to content

fix: sink events as they happen#24

Closed
0xgleb wants to merge 2 commits into
masterfrom
fix/sqlite-es-batch-event-insert
Closed

fix: sink events as they happen#24
0xgleb wants to merge 2 commits into
masterfrom
fix/sqlite-es-batch-event-insert

Conversation

@0xgleb

@0xgleb 0xgleb commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Inserting events one row at a time requires a separate round trip to SQLite for each event, which becomes a bottleneck when persisting many events in a single transaction. A batched approach is needed to reduce round trips and improve throughput.

Solution

  • Replaced the per-event INSERT loop with a new insert_serialized_events_batch function that uses sqlx::QueryBuilder to emit multi-row INSERT statements.
  • Batches are capped at 142 rows each to stay within SQLite's 999 bind-parameter limit (7 columns × 142 rows = 994 binds).
  • Exposed insert_serialized_events_batch as a public function from sqlite-es so that event-sorcery can reuse it directly rather than duplicating the insertion logic.
  • Replaced the local is_optimistic_lock_error helper and manual error mapping in event-sorcery with a map_sqlite_aggregate_error function that converts SqliteAggregateError variants exhaustively into SqliteEventRepositoryError.
  • Removed the insert_event query builder method from SqlQueryFactory in favour of a new events_table accessor that supplies the table name to the shared batch insert function.

0xgleb and others added 2 commits June 12, 2026 18:07
Replace per-row INSERT loops with multi-row INSERT batches so commits
with several events hit SQLite once per batch instead of once per event.

Co-authored-by: Cursor <cursoragent@cursor.com>
Reuse sqlite_es::insert_serialized_events_batch instead of issuing one
INSERT per event from the event-sorcery repository wrapper.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

More reviews will be available in 48 minutes and 50 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cfad152b-047f-4403-b326-b485b2825c1d

📥 Commits

Reviewing files that changed from the base of the PR and between d0ad3f6 and 96b15a1.

📒 Files selected for processing (4)
  • crates/event-sorcery/src/sqlite_event_repository.rs
  • crates/sqlite-es/src/event_repository.rs
  • crates/sqlite-es/src/lib.rs
  • crates/sqlite-es/src/sql_query.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sqlite-es-batch-event-insert

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.

0xgleb commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

How to use the Graphite Merge Queue

Add the label add-to-gt-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@0xgleb 0xgleb changed the title fix(sqlite-es): batch-insert persisted events in one statement fix: sink events as they happen Jun 12, 2026
@0xgleb 0xgleb marked this pull request as ready for review June 12, 2026 21:23
@0xgleb 0xgleb self-assigned this Jun 12, 2026
@0xgleb 0xgleb requested review from JuaniRios and findolor June 12, 2026 21:58
@graphite-app

graphite-app Bot commented Jun 15, 2026

Copy link
Copy Markdown

Merge activity

  • Jun 15, 7:20 PM UTC: 0xgleb added this pull request to the Graphite merge queue.
  • Jun 15, 7:21 PM UTC: CI is running for this pull request on a draft pull request (#26) due to your merge queue CI optimization settings.
  • Jun 15, 7:26 PM UTC: Merged by the Graphite merge queue via draft PR: #26.

@graphite-app graphite-app Bot closed this Jun 15, 2026
@graphite-app graphite-app Bot deleted the fix/sqlite-es-batch-event-insert branch June 15, 2026 19:26
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.

3 participants