From bb725d6de95c1b89142d51fb4ec69cbeb042e0cb Mon Sep 17 00:00:00 2001 From: Matt Sullivan Date: Mon, 10 Oct 2011 15:37:19 +1000 Subject: [PATCH] Fix InMemoryBufferedBrowsableElementStore incorrectly discarding events FetchFromPersistentStoreAndCorrelateWithBuffer would enumerate the persistent data store events multiple times, leading to events discarded and not returned. --- .../Ncqrs.EventBus/InMemoryBufferedBrowsableElementStore.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Extensions/src/Ncqrs.EventBus/InMemoryBufferedBrowsableElementStore.cs b/Extensions/src/Ncqrs.EventBus/InMemoryBufferedBrowsableElementStore.cs index 3c3da023..2cfadb30 100644 --- a/Extensions/src/Ncqrs.EventBus/InMemoryBufferedBrowsableElementStore.cs +++ b/Extensions/src/Ncqrs.EventBus/InMemoryBufferedBrowsableElementStore.cs @@ -41,7 +41,11 @@ private IEnumerable FetchFromBuffer() private IEnumerable FetchFromPersistentStoreAndCorrelateWithBuffer(string pipelineName) { - var fetchedFromPersistentStore = _persistentStore.Fetch(pipelineName, _fetchSize); + // We need to copy the fetched items to prevent fetchedFromPersistentStore.Any() + // and/or CorrelateWithBufffer consuming events and not returning them. + // Rx extensions MemoizeAll would be a good solution, but I'm not sure we want + // an extra dependency, ToList is fine as long as _fetchSize is reasonable. + var fetchedFromPersistentStore = _persistentStore.Fetch(pipelineName, _fetchSize).ToList(); if (!fetchedFromPersistentStore.Any() || CorrelateWithBufffer(fetchedFromPersistentStore)) { _inMemoryMode = true;