This adds snapshot capability to eventstore and aggregatestore. With given strategy saves a snapshot of aggregate and loads next time and remaining events wich can increase load times of long-living aggregates
Affected Components
Event Store(Mongodb, memory)
AggregateSttore
Related Issues
None
Solution and Design
A eventstore implemtation can now implement eh.SnapshotStore an now store snaphots of current state in aggregate.
every aggregate that want to be snapshotted needs to implement eh.Snapshotable
type Snapshotable interface {
CreateSnapshot() *Snapshot
ApplySnapshot(snapshot *Snapshot)
}
Loading
When aggretate i requested to be loaded the store checks if aggretate implements eh.Snapshotable and tries to find latest snapshot for aggregate. Loads and applies snapshot then loads all events that is not applies in current snapshot.
Saving
When aggretate i requested to be saved the store checks if aggretate implements eh.Snapshotable and if the strategy return true we create a snapshot ans saves it alongside the events.
Coverage decreased (-1.06%) to 67.542% when pulling 4f802e8b9c0f07c7a76b61325be0a1ddf1d9a72e on klowdo:eventstore-snapshot into f8fe1ad7457f209f888d14a641813a7c104b89ab on looplab:main.
Description
This adds snapshot capability to eventstore and aggregatestore. With given strategy saves a snapshot of aggregate and loads next time and remaining events wich can increase load times of long-living aggregates
Affected Components
Related Issues
None
Solution and Design
A eventstore implemtation can now implement
eh.SnapshotStore
an now store snaphots of current state in aggregate.every aggregate that want to be snapshotted needs to implement
eh.Snapshotable
Loading
When aggretate i requested to be loaded the store checks if aggretate implements
eh.Snapshotable
and tries to find latest snapshot for aggregate. Loads and applies snapshot then loads all events that is not applies in current snapshot.Saving
When aggretate i requested to be saved the store checks if aggretate implements
eh.Snapshotable
and if the strategy return true we create a snapshot ans saves it alongside the events.Steps to test and verify
EveryNumberEventSnapshotStrateg
<- set to every 1PeriodSnapshotStrategy
NoSnapshotStrategy
ehSnapshotable
in longliving aggregate