diff --git a/src/Repository/DefaultRepository.php b/src/Repository/DefaultRepository.php index de58dedfc..eacdfa70f 100644 --- a/src/Repository/DefaultRepository.php +++ b/src/Repository/DefaultRepository.php @@ -281,17 +281,25 @@ private function archive(Message ...$messages): void return; } + $lastMessageWithNewStreamStart = null; + foreach ($messages as $message) { if (!$message->newStreamStart()) { continue; } - $this->store->archiveMessages( - $message->aggregateClass(), - $message->aggregateId(), - $message->playhead(), - ); + $lastMessageWithNewStreamStart = $message; + } + + if ($lastMessageWithNewStreamStart === null) { + return; } + + $this->store->archiveMessages( + $lastMessageWithNewStreamStart->aggregateClass(), + $lastMessageWithNewStreamStart->aggregateId(), + $lastMessageWithNewStreamStart->playhead(), + ); } /** @return Traversable */