forked from neos/neos-development-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGFIX: Flush content cache on discard all
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
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Neos.Neos/Classes/Fusion/Cache/WorkspaceProjectorCatchUpHookForCacheFlushing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Neos.Neos/Classes/Fusion/Cache/WorkspaceProjectorCatchUpHookForCacheFlushingFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters