Skip to content

Commit d0c1d3c

Browse files
committed
BUGFIX: drastically improve performance when working with many nodes
1 parent f81a94c commit d0c1d3c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Sandstorm\NeosAcl\Performance;
4+
5+
use Neos\Flow\Aop\JoinPointInterface;
6+
use Neos\Flow\Annotations as Flow;
7+
8+
/**
9+
* the NodePrivilegeContext does not cache the Node references;
10+
* but instead fetches them again and again (for every node
11+
* check) from the DB.
12+
*
13+
* This is a hotfix, which adds the cache in an aspect.
14+
*
15+
* @Flow\Scope("singleton")
16+
* @Flow\Aspect
17+
*/
18+
class NodeContextPerformanceAspect
19+
{
20+
21+
protected $nodeCache = [];
22+
23+
/**
24+
* @Flow\Around("method(Neos\ContentRepository\Security\Authorization\Privilege\Node\NodePrivilegeContext->getNodeByIdentifier())")
25+
* @return void
26+
*/
27+
public function boot(JoinPointInterface $joinPoint)
28+
{
29+
$nodeIdentifier = $joinPoint->getMethodArgument('nodeIdentifier');
30+
if (array_key_exists($nodeIdentifier, $this->nodeCache)) {
31+
return $this->nodeCache[$nodeIdentifier];
32+
}
33+
34+
$result = $joinPoint->getAdviceChain()->proceed($joinPoint);
35+
$this->nodeCache[$nodeIdentifier] = $result;
36+
return $result;
37+
}
38+
}

0 commit comments

Comments
 (0)