Skip to content

Skip reindexing when commit() creates a new write stream#300

Merged
albe merged 1 commit intomainfrom
copilot/add-toggle-to-create-stream-method
Apr 30, 2026
Merged

Skip reindexing when commit() creates a new write stream#300
albe merged 1 commit intomainfrom
copilot/add-toggle-to-create-stream-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

createEventStream always reindexes the full store when creating a new stream. For ad-hoc read streams this is necessary, but for write streams created implicitly by commit(), no existing event can ever match the brand-new stream name — reindexing is wasted work.

Changes

  • WritableStorage.ensureIndex(name, matcher, reindex = true) — added reindex flag; when false, skips the forEachDocument scan and registers the new index empty.
  • EventStore.createEventStream(streamName, matcher, reindex = true) — threads the flag through to ensureIndex. Public default remains true, preserving existing behaviour for ad-hoc read streams.
  • EventStore.commit() — passes reindex: false when auto-creating a write stream, since uniqueness of the stream name guarantees zero historical matches.
// Ad-hoc read stream: reindexes to find all matching existing events (default)
eventstore.createEventStream('my-projection', e => e.payload.type === 'OrderPlaced');

// Write stream via commit(): new stream index starts empty, no scan needed
eventstore.commit('order-123', [{ type: 'OrderPlaced' }]);

@albe albe marked this pull request as ready for review April 30, 2026 14:42
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 98.154% (+0.03%) from 98.127% — copilot/add-toggle-to-create-stream-method into main

@albe albe merged commit 61f3bb3 into main Apr 30, 2026
13 checks passed
@albe albe deleted the copilot/add-toggle-to-create-stream-method branch April 30, 2026 17:55
Copilot AI added a commit that referenced this pull request May 1, 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.

3 participants