Class: Synapse::EventStore::Mongo::DocumentPerCommitStrategy
- Inherits:
-
StorageStrategy
- Object
- StorageStrategy
- Synapse::EventStore::Mongo::DocumentPerCommitStrategy
- Defined in:
- lib/synapse/event_store/mongo/per_commit_strategy.rb
Overview
Storage strategy that stores all events in a commit operation in a single document
Since Mongo doesn’t support transactions, this can be used as a substitute to guarantee atomic storage of events. The only downside is that it may be harder to query events from the event store.
Performance also seems to be better using this strategy
Defined Under Namespace
Classes: CommitDocument, DocumentDomainEventData, EventDocument
Constant Summary
Constants inherited from StorageStrategy
StorageStrategy::ASCENDING, StorageStrategy::DESCENDING
Instance Method Summary collapse
Methods inherited from StorageStrategy
#ensure_indexes, #fetch_events, #fetch_last_snapshot, #initialize
Constructor Details
This class inherits a constructor from Synapse::EventStore::Mongo::StorageStrategy
Instance Method Details
#create_documents(type_identifier, events) ⇒ Array
15 16 17 18 |
# File 'lib/synapse/event_store/mongo/per_commit_strategy.rb', line 15 def create_documents(type_identifier, events) document = CommitDocument.new document.from_events(type_identifier, events, @serializer).to_hash end |
#extract_events(hash, aggregate_id) ⇒ Array
23 24 25 26 |
# File 'lib/synapse/event_store/mongo/per_commit_strategy.rb', line 23 def extract_events(hash, aggregate_id) document = CommitDocument.new document.from_hash(hash).to_events(aggregate_id, @serializer, @upcaster_chain) end |