Skip to content

Commit b916bae

Browse files
committed
MAGETWO-96463: Add caching to improve admin performance
- remove caching in view config
1 parent ed85d0b commit b916bae

File tree

2 files changed

+10
-72
lines changed
  • dev/tests/integration/testsuite/Magento/Theme/Model/View
  • lib/internal/Magento/Framework/Config

2 files changed

+10
-72
lines changed

dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ public function testGetConfigCustomized()
203203
<view><vars module="Namespace_Module"><var name="customVar">custom value</var></vars></view>'
204204
);
205205

206-
\Magento\TestFramework\Helper\CacheCleaner::cleanAll();
207-
208206
$config = $this->_viewConfig->getViewConfig();
209207
$this->assertInstanceOf(\Magento\Framework\Config\View::class, $config);
210208
$this->assertEquals(['customVar' => 'custom value'], $config->getVars('Namespace_Module'));

lib/internal/Magento/Framework/Config/View.php

Lines changed: 10 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
*/
66
namespace Magento\Framework\Config;
77

8-
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
9-
use Magento\Framework\App\ObjectManager;
10-
use Magento\Framework\Serialize\SerializerInterface;
11-
use Magento\Framework\Serialize\Serializer\Json;
12-
use Magento\Framework\View\DesignInterface;
13-
148
/**
159
* View configuration files handler
1610
*
@@ -30,26 +24,6 @@ class View extends \Magento\Framework\Config\Reader\Filesystem
3024
*/
3125
protected $data;
3226

33-
/**
34-
* @var LayoutCache
35-
*/
36-
private $layoutCache;
37-
38-
/**
39-
* @var SerializerInterface
40-
*/
41-
private $serializer;
42-
43-
/**
44-
* @var array
45-
*/
46-
private $scopedLayoutCache;
47-
48-
/**
49-
* @var DesignInterface
50-
*/
51-
private $design;
52-
5327
/**
5428
* @param FileResolverInterface $fileResolver
5529
* @param ConverterInterface $converter
@@ -60,10 +34,6 @@ class View extends \Magento\Framework\Config\Reader\Filesystem
6034
* @param string $domDocumentClass
6135
* @param string $defaultScope
6236
* @param array $xpath
63-
* @param LayoutCache|null $layoutCache
64-
* @param SerializerInterface|null $serializer
65-
* @param DesignInterface|null $design
66-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6737
*/
6838
public function __construct(
6939
FileResolverInterface $fileResolver,
@@ -74,14 +44,10 @@ public function __construct(
7444
$idAttributes = [],
7545
$domDocumentClass = \Magento\Framework\Config\Dom::class,
7646
$defaultScope = 'global',
77-
$xpath = [],
78-
LayoutCache $layoutCache = null,
79-
SerializerInterface $serializer = null,
80-
DesignInterface $design = null
47+
$xpath = []
8148
) {
8249
$this->xpath = $xpath;
8350
$idAttributes = $this->getIdAttributes();
84-
8551
parent::__construct(
8652
$fileResolver,
8753
$converter,
@@ -92,9 +58,6 @@ public function __construct(
9258
$domDocumentClass,
9359
$defaultScope
9460
);
95-
$this->layoutCache = $layoutCache ?? ObjectManager::getInstance()->get(LayoutCache::class);
96-
$this->serializer = $serializer ?? ObjectManager::getInstance()->get(Json::class);
97-
$this->design = $design ?? ObjectManager::getInstance()->get(DesignInterface::class);
9861
}
9962

10063
/**
@@ -236,45 +199,22 @@ protected function initData()
236199
}
237200

238201
/**
239-
* @inheritdoc
240-
*
241-
* @throws \InvalidArgumentException
202+
* {@inheritdoc}
242203
* @since 100.1.0
243204
*/
244205
public function read($scope = null)
245206
{
246207
$scope = $scope ?: $this->_defaultScope;
247-
$layoutCacheKey = implode(
248-
'-',
249-
[
250-
__CLASS__,
251-
$scope,
252-
$this->_fileName,
253-
$this->design->getArea(),
254-
$this->serializer->serialize($this->xpath)
255-
]
256-
);
257-
if (!isset($this->scopedLayoutCache[$layoutCacheKey])) {
258-
if ($data = $this->layoutCache->load($layoutCacheKey)) {
259-
$this->scopedLayoutCache[$layoutCacheKey] = $this->serializer->unserialize($data);
260-
} else {
261-
$result = [];
262-
263-
$parents = (array)$this->_fileResolver->getParents($this->_fileName, $scope);
264-
// Sort parents desc
265-
krsort($parents);
208+
$result = [];
266209

267-
foreach ($parents as $parent) {
268-
$result = array_replace_recursive($result, $this->_readFiles([$parent]));
269-
}
210+
$parents = (array)$this->_fileResolver->getParents($this->_fileName, $scope);
211+
// Sort parents desc
212+
krsort($parents);
270213

271-
$this->scopedLayoutCache[$layoutCacheKey] = array_replace_recursive($result, parent::read($scope));
272-
$this->layoutCache->save(
273-
$this->serializer->serialize($this->scopedLayoutCache[$layoutCacheKey]),
274-
$layoutCacheKey
275-
);
276-
}
214+
foreach ($parents as $parent) {
215+
$result = array_replace_recursive($result, $this->_readFiles([$parent]));
277216
}
278-
return $this->scopedLayoutCache[$layoutCacheKey];
217+
218+
return array_replace_recursive($result, parent::read($scope));
279219
}
280220
}

0 commit comments

Comments
 (0)