Get a review of the NEventStore chapter

I have a new ES stream that already has half a million events (no snapshots yet ... I know, I get there) and a simple client that atm only adds (even more) events.

NEventStore.OpenStream(int.MinValue, int.MaxValue) takes a very long time to open a stream first; after which I save the last revision, and then only NEventStore.OpenStream(lastRevision, int.MaxValue) to add again. The problem is only on initial startup.

Is there a mechanism inside NEventStore either simply add without opening, or define a head revision without opening the entire stream, so I can open it from the latest version and add it. Of course, I could also go directly to the database and queries, but given the dependency, I feel like I don't need to.

+5
source share
1 answer

You already mentioned a possible solution: snapshots.

This example opens the stream from the last snapshot and adds a new snapshot after the events take place.

 // Get the latest snapshot var latestSnapshot = _eventStore.Advanced.GetSnapshot(streamId, int.MaxValue); // Open the stream from the snapshot if there is one, otherwise open the stream as normal using (var stream = latestSnapshot == null ? _eventStore.OpenStream(streamId) : _eventStore.OpenStream(latestSnapshot, int.MaxValue)) { // Add events and commit stream.Add(new EventMessage()); stream.CommitChanges(Guid.NewGuid()); // Add a new snapshot (with no payload) _eventStore.Advanced.AddSnapshot( new Snapshot(streamId, stream.StreamRevision, string.Empty)); } 

Most likely, it is not necessary to add new pictures. This is just an example showing how snapshots work.

+3
source

Source: https://habr.com/ru/post/1212381/


All Articles