Skip to content

Commit

Permalink
make command handling faster for some use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jan 31, 2017
1 parent 1e298f0 commit edea6e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions lib/defaultCommandHandler.js
Expand Up @@ -9,7 +9,8 @@ var Definition = require('./definitionBase'),
uuid = require('uuid').v4,
ConcurrencyError = require('./errors/concurrencyError'),
AggregateDestroyedError = require('./errors/aggregateDestroyedError'),
AggregateConcurrencyError = require('./errors/aggregateConcurrencyError');
AggregateConcurrencyError = require('./errors/aggregateConcurrencyError'),
EventFromEventStore = require('eventstore/lib/event');

/**
* Returns a random number between passed values of min and max.
Expand Down Expand Up @@ -724,6 +725,14 @@ _.extend(DefaultCommandHandler.prototype, {

var self = this;

var evtsToDispatch = [];
var fakeEventStream = {
aggregateId: dotty.get(uncommitedEvents[0], self.definitions.event.aggregateId),
aggregate: dotty.get(uncommitedEvents[0], self.definitions.event.aggregate),
context: dotty.get(uncommitedEvents[0], self.definitions.event.context),
uncommittedEvents: []
};

for (var e in uncommitedEvents) {
var evt = uncommitedEvents[e];

Expand All @@ -739,9 +748,14 @@ _.extend(DefaultCommandHandler.prototype, {
}

if (stream) stream.addEvent(evt);
}

var evtsToDispatch = [];
if (!stream && self.aggregate.disablePersistence) {
var eventStoreEvent = new EventFromEventStore(fakeEventStream, evt, self.eventStore.eventMappings);
eventStoreEvent.disablePersistence = true;
eventStoreEvent.id = uuid().toString();
evtsToDispatch.push(eventStoreEvent);
}
}

async.each(streams, function (stream, callback) {
if (self.aggregate.disablePersistence) {
Expand Down
2 changes: 1 addition & 1 deletion releasenotes.md
@@ -1,4 +1,4 @@
## [v2.5.3](https://github.com/adrai/node-cqrs-domain/compare/v2.5.2...v2.5.3)
## [v2.5.4](https://github.com/adrai/node-cqrs-domain/compare/v2.5.2...v2.5.4)
- make command handling faster for some use cases

## [v2.5.2](https://github.com/adrai/node-cqrs-domain/compare/v2.5.1...v2.5.2)
Expand Down

0 comments on commit edea6e9

Please sign in to comment.