Fixed snapshotting.
from functools import reduce
-from copy import deepcopy
-
-from eventsourcing.domain.model.entity import TimestampedVersionedEntity
-from eventsourcing.domain.model.snapshot import AbstractSnapshop
from eventsourcing.infrastructure.eventstore import AbstractEventStore
from eventsourcing.infrastructure.snapshotting import AbstractSnapshotStrategy, entity_from_snapshot
@@ -117,12 +113,15 @@ class EventPlayer(object):
if last_snapshot:
# Recover entity by applying to snapshotted state the
# events that occurred since snapshot was taken.
- initial_state = entity_from_snapshot(last_snapshot)
- gt = last_snapshot.entity_version
- entity = self.replay_entity(entity_id, gt=gt, lt=lt, lte=lte, initial_state=initial_state)
+ snapshotted_entity = entity_from_snapshot(last_snapshot)
+ entity = self.replay_entity(entity_id,
+ gt=last_snapshot.entity_version,
+ lte=last_event.entity_version,
+ initial_state=snapshotted_entity
+ )
else:
# Recover entity from scratch.
- entity = self.replay_entity(entity_id, lt=lt, lte=lte)
+ entity = self.replay_entity(entity_id, lte=last_event.entity_version)
# Take snapshot of recovered entity.
snapshot = self.snapshot_strategy.take_snapshot(entity_id, entity, last_event.entity_version)
@@ -140,18 +139,3 @@ class EventPlayer(object):
Returns the most recent event for the given entity ID.
"""
return self.event_store.get_most_recent_event(entity_id, lt=lt, lte=lte)
-
- # def fastforward(self, stale_entity, lt=None, lte=None):
- # assert isinstance(stale_entity, TimestampedVersionedEntity)
- #
- # # Replay the events since the entity version.
- # fresh_entity = self.replay_entity(
- # entity_id=stale_entity.id,
- # gt=stale_entity.version,
- # lt=lt,
- # lte=lte,
- # initial_state=stale_entity,
- # )
- #
- # # Return the fresh instance.
- # return fresh_entity
