Skip to content

Commit

Permalink
Merge pull request #460 from patchlevel/optimaize-archive-logic
Browse files Browse the repository at this point in the history
execute archive logic only once
  • Loading branch information
DavidBadura authored Jan 9, 2024
2 parents baf2ba6 + 4c6e2f7 commit b35940e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Repository/DefaultRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> */
Expand Down

0 comments on commit b35940e

Please sign in to comment.