Skip to content

Commit

Permalink
BUGFIX: Flush content cache on discard all
Browse files Browse the repository at this point in the history
This is achieved via a catch up hook for the workspace projection that
utilized info from the PendingChangesProjection to figure out which
nodes need to be considered for cache invalidation.
  • Loading branch information
grebaldi committed Jun 21, 2024
1 parent 0cd9460 commit 19b95c2
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Neos\Neos\Fusion\Cache;

/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
use Neos\EventStore\Model\EventEnvelope;
use Neos\Neos\PendingChangesProjection\ChangeFinder;

/**
* @internal
*/
class WorkspaceProjectorCatchUpHookForCacheFlushing implements CatchUpHookInterface
{
public function __construct(
private readonly ContentRepository $contentRepository,
private readonly ContentCacheFlusher $contentCacheFlusher
) {
}

public function onBeforeCatchUp(): void
{
}

public function onBeforeEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void
{
if ($eventInstance instanceof WorkspaceWasDiscarded) {
$changeFinder = $this->contentRepository->projectionState(ChangeFinder::class);
$changes = $changeFinder->findByContentStreamId($eventInstance->previousContentStreamId);

foreach ($changes as $change) {
$this->contentCacheFlusher->flushNodeAggregate(
$this->contentRepository,
$eventInstance->workspaceName,
$change->nodeAggregateId
);
}
}
}

public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void
{
}

public function onBeforeBatchCompleted(): void
{
}

public function onAfterCatchUp(): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Neos\Neos\Fusion\Cache;

/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface;

class WorkspaceProjectorCatchUpHookForCacheFlushingFactory implements CatchUpHookFactoryInterface
{
public function __construct(
private readonly ContentCacheFlusher $contentCacheFlusher
) {
}

public function build(ContentRepository $contentRepository): WorkspaceProjectorCatchUpHookForCacheFlushing
{
return new WorkspaceProjectorCatchUpHookForCacheFlushing(
$contentRepository,
$this->contentCacheFlusher
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ Neos:
catchUpHooks:
'Neos.Neos:FlushContentCache':
factoryObjectName: Neos\Neos\Fusion\Cache\GraphProjectorCatchUpHookForCacheFlushingFactory
'Neos.ContentRepository:Workspace':
catchUpHooks:
'Neos.Neos:FlushContentCache':
factoryObjectName: Neos\Neos\Fusion\Cache\WorkspaceProjectorCatchUpHookForCacheFlushingFactory
'Neos.Neos:AssetUsage':
factoryObjectName: Neos\Neos\AssetUsage\Projection\AssetUsageProjectionFactory

0 comments on commit 19b95c2

Please sign in to comment.