Skip to content
Snippets Groups Projects
Commit a3eae5a3 authored by Claus Due's avatar Claus Due Committed by Benni Mack
Browse files

[TASK] Allow generated BE user avatars to be cached

Given the assumption that this particular resource is not
one that changes very often one can benefit from storing
this in the cache_runtime in order to avoid fetching
the same avator more than one in a request.

Change-Id: Idc39c59dc8213f861ef4da7c9da4f5a95cfab9ac
Resolves: #79547
Releases: master
Reviewed-on: https://review.typo3.org/51467


Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Tested-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent 2fd70c83
Branches
Tags
No related merge requests found
......@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Backend\Backend\Avatar;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
......@@ -33,20 +35,6 @@ class Avatar
*/
protected $avatarProviders = [];
/**
* Construct
*/
public function __construct()
{
$this->validateSortAndInitiateAvatarProviders();
$this->view = $this->getFluidTemplateObject();
}
/**
* @var StandaloneView
*/
protected $view;
/**
* Render avatar tag
*
......@@ -57,26 +45,43 @@ class Avatar
*/
public function render(array $backendUser = null, int $size = 32, bool $showIcon = false)
{
if (!is_array($backendUser)) {
$backendUser = $this->getBackendUser()->user;
}
// Icon
$icon = '';
if ($showIcon) {
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$icon = $iconFactory->getIconForRecord('be_users', $backendUser, Icon::SIZE_SMALL)->render();
}
$cacheId = 'avatar_' . md5(
$backendUser['uid'] . '/' .
(string)$size . '/' .
(string)$showIcon);
$avatar = static::getCache()->get($cacheId);
$image = $this->getImgTag($backendUser, $size);
if (!$avatar) {
$this->view->assignMultiple([
'image' => $image,
'icon' => $icon
]
);
$this->validateSortAndInitiateAvatarProviders();
$view = $this->getFluidTemplateObject();
return $this->view->render();
// Icon
$icon = '';
if ($showIcon) {
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$icon = $iconFactory->getIconForRecord('be_users', $backendUser, Icon::SIZE_SMALL)->render();
}
$image = $this->getImgTag($backendUser, $size);
$view->assignMultiple(
[
'image' => $image,
'icon' => $icon
]
);
$avatar = $view->render();
static::getCache()->set($cacheId, $avatar);
}
return $avatar;
}
/**
......@@ -196,4 +201,14 @@ class Avatar
$view->getRequest()->setControllerExtensionName('Backend');
return $view;
}
/**
* @return VariableFrontend
*/
protected function getCache()
{
/** @var CacheManager $manager */
$manager = GeneralUtility::makeInstance(CacheManager::class);
return $manager->getCache('cache_runtime');
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment