From 3aa9ccce73068ade12c138e8cbe349dca10cc091 Mon Sep 17 00:00:00 2001 From: bwaidelich Date: Fri, 11 Aug 2023 11:13:59 +0200 Subject: [PATCH 1/2] FEATURE: Progress bar for projection replay Resolves: #4200 --- .../Classes/ContentRepository.php | 7 +++++-- .../Classes/Projection/CatchUpOptions.php | 10 +++++++++- .../Classes/Command/CrCommandController.php | 9 ++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index 91e63ac6970..e0314b7086f 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -167,11 +167,14 @@ public function catchUpProjection(string $projectionClassName, CatchUpOptions $o $streamName = VirtualStreamName::all(); $eventStream = $this->eventStore->load($streamName); if ($options->maximumSequenceNumber !== null) { - $eventStream = $eventStream->withMaximumSequenceNumber($options->maximumSequenceNumber); + //$eventStream = $eventStream->withMaximumSequenceNumber($options->maximumSequenceNumber); } - $eventApplier = function (EventEnvelope $eventEnvelope) use ($projection, $catchUpHook) { + $eventApplier = function (EventEnvelope $eventEnvelope) use ($projection, $catchUpHook, $options) { $event = $this->eventNormalizer->denormalize($eventEnvelope->event); + if ($options->progressCallback !== null) { + ($options->progressCallback)($event, $eventEnvelope); + } if (!$projection->canHandle($event)) { return; } diff --git a/Neos.ContentRepository.Core/Classes/Projection/CatchUpOptions.php b/Neos.ContentRepository.Core/Classes/Projection/CatchUpOptions.php index 09679cd6d1c..b3d4ef3199c 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/CatchUpOptions.php +++ b/Neos.ContentRepository.Core/Classes/Projection/CatchUpOptions.php @@ -4,8 +4,11 @@ namespace Neos\ContentRepository\Core\Projection; +use Closure; use Neos\ContentRepository\Core\ContentRepository; +use Neos\ContentRepository\Core\EventStore\EventInterface; use Neos\EventStore\Model\Event\SequenceNumber; +use Neos\EventStore\Model\EventEnvelope; /** * Options for {@see ContentRepository::catchUpProjection()} @@ -16,9 +19,11 @@ final class CatchUpOptions { /** * @param SequenceNumber|null $maximumSequenceNumber If specified the catch-up will stop at the specified {@see SequenceNumber} + * @param Closure(EventInterface $event, EventEnvelope $eventEnvelope): void|null $progressCallback If specified the given closure will be invoked for every event with the current {@see EventInterface} and {@see EventEnvelope} passed as arguments */ private function __construct( public readonly ?SequenceNumber $maximumSequenceNumber, + public readonly ?Closure $progressCallback, ) { } @@ -30,12 +35,13 @@ private function __construct( */ public static function create( SequenceNumber|int|null $maximumSequenceNumber = null, + Closure|null $progressCallback = null, ): self { if (is_int($maximumSequenceNumber)) { $maximumSequenceNumber = SequenceNumber::fromInteger($maximumSequenceNumber); } - return new self($maximumSequenceNumber); + return new self($maximumSequenceNumber, $progressCallback); } @@ -47,9 +53,11 @@ public static function create( */ public function with( SequenceNumber|int|null $maximumSequenceNumber = null, + Closure|null $progressCallback = null, ): self { return self::create( $maximumSequenceNumber ?? $this->maximumSequenceNumber, + $progressCallback ?? $this->progressCallback, ); } } diff --git a/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php b/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php index 9ce435fdf15..c50a34e0289 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php +++ b/Neos.ContentRepositoryRegistry/Classes/Command/CrCommandController.php @@ -53,15 +53,18 @@ public function replayCommand(string $projection, string $contentRepository = 'd if (!$quiet) { $this->outputLine('Replaying events for projection "%s" of Content Repository "%s" ...', [$projection, $contentRepositoryId->value]); - // TODO start progress bar + $this->output->progressStart(); } - $options = CatchUpOptions::create(); + $options = CatchUpOptions::create( + progressCallback: fn () => $this->output->progressAdvance(), + ); if ($until > 0) { $options = $options->with(maximumSequenceNumber: SequenceNumber::fromInteger($until)); } $projectionService->replayProjection($projection, $options); if (!$quiet) { - // TODO finish progress bar + $this->output->progressFinish(); + $this->outputLine(); $this->outputLine('Done.'); } } From 530248cd3e0d35bb5f2f5dbb026e8569ad79d81c Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Fri, 11 Aug 2023 12:19:10 +0200 Subject: [PATCH 2/2] Update Neos.ContentRepository.Core/Classes/ContentRepository.php --- Neos.ContentRepository.Core/Classes/ContentRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index e0314b7086f..a5c181a14ec 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -167,7 +167,7 @@ public function catchUpProjection(string $projectionClassName, CatchUpOptions $o $streamName = VirtualStreamName::all(); $eventStream = $this->eventStore->load($streamName); if ($options->maximumSequenceNumber !== null) { - //$eventStream = $eventStream->withMaximumSequenceNumber($options->maximumSequenceNumber); + $eventStream = $eventStream->withMaximumSequenceNumber($options->maximumSequenceNumber); } $eventApplier = function (EventEnvelope $eventEnvelope) use ($projection, $catchUpHook, $options) {