performance improvements (#2329)

* remove work from constructor
* refactor twig extensions
* upgrade theme
* replace sub-request with direct template rendering
This commit is contained in:
Kevin Papst
2021-02-20 23:52:01 +01:00
committed by GitHub
parent 9eb25c412e
commit 607d09aefb
40 changed files with 992 additions and 1092 deletions

View File

@@ -20,22 +20,17 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
/**
* Allows dynamic injection of theme related options.
*/
class ThemeOptionsSubscriber implements EventSubscriberInterface
final class ThemeOptionsSubscriber implements EventSubscriberInterface
{
/**
* @var TokenStorageInterface
*/
protected $storage;
private $storage;
/**
* @var ContextHelper
*/
protected $helper;
private $helper;
/**
* @param TokenStorageInterface $storage
* @param ContextHelper $helper
*/
public function __construct(TokenStorageInterface $storage, ContextHelper $helper)
{
$this->storage = $storage;
@@ -52,18 +47,24 @@ class ThemeOptionsSubscriber implements EventSubscriberInterface
];
}
/**
* @param KernelEvent $event
*/
public function setThemeOptions(KernelEvent $event)
public function setThemeOptions(KernelEvent $event): void
{
if (!$this->canHandleEvent($event)) {
// Ignore sub-requests
if (!$event->isMasterRequest()) {
return;
}
// ignore events like the toolbar where we do not have a token
if (null === $this->storage->getToken()) {
return;
}
/** @var User $user */
$user = $this->storage->getToken()->getUser();
if (!($user instanceof User)) {
return;
}
/** @var UserPreference $ref */
foreach ($user->getPreferences() as $ref) {
$name = $ref->getName();
@@ -90,26 +91,4 @@ class ThemeOptionsSubscriber implements EventSubscriberInterface
}
}
}
/**
* @param KernelEvent $event
* @return bool
*/
protected function canHandleEvent(KernelEvent $event): bool
{
// Ignore sub-requests
if (!$event->isMasterRequest()) {
return false;
}
// ignore events like the toolbar where we do not have a token
if (null === $this->storage->getToken()) {
return false;
}
/** @var User $user */
$user = $this->storage->getToken()->getUser();
return ($user instanceof User);
}
}