Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Make AccessDecisionManager much faster #49670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class AccessDecisionManager implements AccessDecisionManagerInterface
private iterable $voters;
private array $votersCacheAttributes = [];
private array $votersCacheObject = [];
private array $nonCachableVoters = [];
private array $cachedVoters = [];

private AccessDecisionStrategyInterface $strategy;

/**
Expand Down Expand Up @@ -87,13 +90,28 @@ private function getVoters(array $attributes, $object = null): iterable
}
// use `get_class` to handle anonymous classes
$keyObject = \is_object($object) ? $object::class : get_debug_type($object);

foreach ($keyAttributes as $keyAttribute) {
if (isset($this->cachedVoters[$keyAttribute][$keyObject])) {
$voters = $this->nonCachableVoters + $this->cachedVoters[$keyAttribute][$keyObject];
ksort($voters);

yield from $voters;

return;
}
}

$voters = [];
foreach ($this->voters as $key => $voter) {
if (!$voter instanceof CacheableVoterInterface) {
yield $voter;
$this->nonCachableVoters[$key] = $voter;
$voters[] = $voter;
continue;
}

$supports = true;
$supportedAttributes = [];
// The voter supports the attributes if it supports at least one attribute of the list
foreach ($keyAttributes as $keyAttribute) {
if (null === $keyAttribute) {
Expand All @@ -104,10 +122,10 @@ private function getVoters(array $attributes, $object = null): iterable
$supports = $this->votersCacheAttributes[$keyAttribute][$key];
}
if ($supports) {
break;
$supportedAttributes[] = $keyAttribute;
}
}
if (!$supports) {
if (!$supports && [] === $supportedAttributes) {
continue;
}

Expand All @@ -119,7 +137,14 @@ private function getVoters(array $attributes, $object = null): iterable
if (!$supports) {
continue;
}
yield $voter;

foreach ($supportedAttributes as $supportedAttribute) {
$this->cachedVoters[$supportedAttribute][$keyObject][$key] = $voter;
}

$voters[] = $voter;
}

yield from $voters;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.