Skip to content

Commit

Permalink
Adjust to beta 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Nov 6, 2024
1 parent 4e9c029 commit c739630
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
11 changes: 11 additions & 0 deletions Classes/Application/CacheTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ final public static function forEverything(
);
}

final public static function forWorkspace(
ContentRepositoryId $contentRepositoryId,
WorkspaceName $workspaceName,
): self {
return new self(
'Workspace'
. self::renderContentRepositoryPrefix($contentRepositoryId)
. self::renderWorkspacePrefix($workspaceName)
);
}

final public static function forNodeAggregate(
ContentRepositoryId $contentRepositoryId,
?WorkspaceName $workspaceName,
Expand Down
7 changes: 6 additions & 1 deletion Classes/Application/ContentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ private function resolveCacheSegmentForContentCollection(
assert($contentCollection instanceof Node);
$cacheTags = new CacheTagSet(
CacheTag::forAncestorNodeFromNode($contentCollection),
CacheTag::forNodeAggregateFromNode($contentCollection)
CacheTag::forNodeAggregateFromNode($contentCollection),
CacheTag::forWorkspace(
$runtimeVariables->subgraph->getContentRepositoryId(),
$runtimeVariables->subgraph->getWorkspaceName()
),
CacheTag::forEverything(null, null),
);
$content = new ComponentCollection(... array_map(
// We can't use an arrow function here because we need to modify $cacheTags
Expand Down
61 changes: 44 additions & 17 deletions Classes/Infrastructure/ComponentCacheFlusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

namespace Nezaniel\ComponentView\Infrastructure;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\AssetVariantInterface;
use Neos\Neos\Fusion\Cache\FlushNodeAggregateRequest;
use Neos\Neos\Fusion\Cache\FlushWorkspaceRequest;
use Nezaniel\ComponentView\Application\CacheTag;
use Nezaniel\ComponentView\Application\CacheTagSet;
use Nezaniel\ComponentView\Application\ComponentCache;
Expand All @@ -31,37 +30,65 @@ public function __construct(
) {
}

#[Flow\Around('method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->flushWorkspace())')]
public function flushWorkspace(JoinPointInterface $joinPoint): void
{
/** @var FlushWorkspaceRequest $flushWorkspaceRequest */
$flushWorkspaceRequest = $joinPoint->getMethodArgument('flushWorkspaceRequest');

$cacheTags = [
CacheTag::forEverything(null, null),
CacheTag::forEverything(
$flushWorkspaceRequest->contentRepositoryId,
$flushWorkspaceRequest->workspaceName
),
CacheTag::forWorkspace(
$flushWorkspaceRequest->contentRepositoryId,
$flushWorkspaceRequest->workspaceName
)
];

$this->cache->clearByTags(new CacheTagSet(...$cacheTags));
}

#[Flow\Around('method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->flushNodeAggregate())')]
public function flushNodeAggregate(JoinPointInterface $joinPoint): void
{
/** @var ContentRepository $contentRepository */
$contentRepository = $joinPoint->getMethodArgument('contentRepository');
/** @var WorkspaceName $workspaceName */
$workspaceName = $joinPoint->getMethodArgument('workspaceName');
/** @var NodeAggregateId $nodeAggregateId */
$nodeAggregateId = $joinPoint->getMethodArgument('nodeAggregateId');
/** @var FlushNodeAggregateRequest $flushNodeAggregateRequest */
$flushNodeAggregateRequest = $joinPoint->getMethodArgument('flushNodeAggregateRequest');

$cacheTags = [
CacheTag::forEverything(null, null),
CacheTag::forEverything($contentRepository->id, $workspaceName),
CacheTag::forNodeAggregate($contentRepository->id, $workspaceName, $nodeAggregateId)
CacheTag::forEverything(
$flushNodeAggregateRequest->contentRepositoryId,
$flushNodeAggregateRequest->workspaceName
),
CacheTag::forNodeAggregate(
$flushNodeAggregateRequest->contentRepositoryId,
$flushNodeAggregateRequest->workspaceName,
$flushNodeAggregateRequest->nodeAggregateId
)
];
$ancestorNodeAggregates = $contentRepository->getContentGraph($workspaceName)->findParentNodeAggregates($nodeAggregateId);

$cacheTags = array_merge($cacheTags, array_map(
fn (NodeAggregate $ancestorAggregate): CacheTag => CacheTag::forAncestorNode($contentRepository->id, $workspaceName, $ancestorAggregate->nodeAggregateId),
iterator_to_array($ancestorNodeAggregates),
fn (NodeAggregateId $ancestorAggregateId): CacheTag => CacheTag::forAncestorNode(
$flushNodeAggregateRequest->contentRepositoryId,
$flushNodeAggregateRequest->workspaceName,
$ancestorAggregateId
),
array_values(iterator_to_array($flushNodeAggregateRequest->ancestorNodeAggregateIds)),
));

$contentRepository = $this->contentRepositoryRegistry->get($contentRepository->id);
$nodeAggregate = $contentRepository->getContentGraph($workspaceName)->findNodeAggregateById($nodeAggregateId);
$contentRepository = $this->contentRepositoryRegistry->get($flushNodeAggregateRequest->contentRepositoryId);
$nodeAggregate = $contentRepository->getContentGraph($flushNodeAggregateRequest->workspaceName)->findNodeAggregateById($flushNodeAggregateRequest->nodeAggregateId);
if ($nodeAggregate) {
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($nodeAggregate->nodeTypeName);
foreach (
$nodeType
? $this->resolveAllSuperTypeNames($nodeType)
: [] as $nodeTypeName
) {
$cacheTags[] = CacheTag::forNodeTypeName($contentRepository->id, $workspaceName, $nodeTypeName);
$cacheTags[] = CacheTag::forNodeTypeName($flushNodeAggregateRequest->contentRepositoryId, $flushNodeAggregateRequest->workspaceName, $nodeTypeName);
}
}

Expand Down

0 comments on commit c739630

Please sign in to comment.