Skip to content

Commit 57d8bf0

Browse files
committed
OXDEV-9981 Cache chain
1 parent 89e3641 commit 57d8bf0

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

CHANGELOG-2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66
- Template Filter to sanitize HTML content
77
- PHP v8.5 support
8+
- Cache template chains and use cached module paths to improve rendering performance
89

910
### Changed
1011
- Extension include_content uses HTML sanitizer

src/Resolver/TemplateChain/TemplateChainResolver.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class TemplateChainResolver implements TemplateChainResolverInterface
1515
{
1616
private array $lastChildCache = [];
17+
private array $parentCache = [];
1718

1819
public function __construct(
1920
private TemplateChainBuilderInterface $templateChainBuilder,
@@ -23,11 +24,15 @@ public function __construct(
2324

2425
public function getParent(string $templateName): string
2526
{
26-
$templateType = $this->templateTypeFactory->createFromTemplateName($templateName);
27-
return $this->templateChainBuilder
28-
->getChain($templateType)
29-
->getParent($templateType)
30-
->getFullyQualifiedName();
27+
if (!isset($this->parentCache[$templateName])) {
28+
$templateType = $this->templateTypeFactory->createFromTemplateName($templateName);
29+
$this->parentCache[$templateName] = $this->templateChainBuilder
30+
->getChain($templateType)
31+
->getParent($templateType)
32+
->getFullyQualifiedName();
33+
}
34+
35+
return $this->parentCache[$templateName];
3136
}
3237

3338
public function getLastChild(string $templateName): string

src/Resolver/TemplateChain/TemplateChainSorter.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
class TemplateChainSorter implements TemplateChainSorterInterface
2020
{
21+
private array $chainCache = [];
22+
2123
public function __construct(
2224
private SortingConfigurationValidatorInterface $sortingConfigurationValidator,
2325
private ShopConfigurationDaoInterface $shopConfigurationDao,
@@ -28,11 +30,15 @@ public function __construct(
2830

2931
public function sort(TemplateChain $unsortedChain, TemplateTypeInterface $extendedTemplate): TemplateChain
3032
{
31-
$sortingConfiguration = $this->shopConfigurationDao
32-
->get($this->context->getCurrentShopId())
33-
->getModuleTemplateExtensionChain();
33+
$shopId = $this->context->getCurrentShopId();
34+
35+
if (!isset($this->chainCache[$shopId])) {
36+
$this->chainCache[$shopId] = $this->shopConfigurationDao
37+
->get($shopId)
38+
->getModuleTemplateExtensionChain();
39+
}
3440

35-
return $this->getSortedChain($unsortedChain, $sortingConfiguration, $extendedTemplate);
41+
return $this->getSortedChain($unsortedChain, $this->chainCache[$shopId], $extendedTemplate);
3642
}
3743

3844
private function getSortedChain(

0 commit comments

Comments
 (0)