Skip to content

Commit 4361fda

Browse files
author
Igor Melnikov
authored
Merge pull request #3473 from magento-performance/2.3.0-qwerty-perf
[2.3.0] Fix performance issues
2 parents 56a2b7f + ae93b34 commit 4361fda

File tree

14 files changed

+146
-102
lines changed

14 files changed

+146
-102
lines changed

app/code/Magento/Backend/Block/Page/Footer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
}
4141

4242
/**
43-
* @return void
43+
* @inheritdoc
4444
*/
4545
protected function _construct()
4646
{
@@ -57,4 +57,12 @@ public function getMagentoVersion()
5757
{
5858
return $this->productMetadata->getVersion();
5959
}
60+
61+
/**
62+
* @inheritdoc
63+
*/
64+
protected function getCacheLifetime()
65+
{
66+
return 3600 * 24 * 10;
67+
}
6068
}

app/code/Magento/CatalogSearch/Test/Mftf/ActionGroup/StorefrontCatalogSearchActionGroup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<submitForm selector="#search_mini_form" parameterArray="['q' => '{{phrase}}']" stepKey="fillQuickSearch" />
1717
<seeInCurrentUrl url="{{StorefrontCatalogSearchPage.url}}" stepKey="checkUrl"/>
1818
<seeInTitle userInput="Search results for: '{{phrase}}'" stepKey="assertQuickSearchTitle"/>
19+
<dontSeeInCurrentUrl url="form_key=" stepKey="checkUrlFormKey"/>
1920
<see userInput="Search results for: '{{phrase}}'" selector="{{StorefrontCatalogSearchMainSection.SearchTitle}}" stepKey="assertQuickSearchName"/>
2021
</actionGroup>
2122

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Serialize\SerializerInterface;
1717
use Magento\Store\Model\Config\Processor\Fallback;
1818
use Magento\Store\Model\ScopeInterface as StoreScope;
19+
use Magento\Framework\Encryption\Encryptor;
1920

2021
/**
2122
* System configuration type
@@ -70,6 +71,11 @@ class System implements ConfigTypeInterface
7071
*/
7172
private $availableDataScopes;
7273

74+
/**
75+
* @var Encryptor
76+
*/
77+
private $encryptor;
78+
7379
/**
7480
* @param ConfigSourceInterface $source
7581
* @param PostProcessorInterface $postProcessor
@@ -79,9 +85,11 @@ class System implements ConfigTypeInterface
7985
* @param PreProcessorInterface $preProcessor
8086
* @param int $cachingNestedLevel
8187
* @param string $configType
82-
* @param Reader $reader
88+
* @param Reader|null $reader
89+
* @param Encryptor|null $encryptor
8390
*
8491
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
92+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8593
*/
8694
public function __construct(
8795
ConfigSourceInterface $source,
@@ -92,17 +100,19 @@ public function __construct(
92100
PreProcessorInterface $preProcessor,
93101
$cachingNestedLevel = 1,
94102
$configType = self::CONFIG_TYPE,
95-
Reader $reader = null
103+
Reader $reader = null,
104+
Encryptor $encryptor = null
96105
) {
97106
$this->postProcessor = $postProcessor;
98107
$this->cache = $cache;
99108
$this->serializer = $serializer;
100109
$this->configType = $configType;
101110
$this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class);
111+
$this->encryptor = $encryptor ?: ObjectManager::getInstance()->get(\Magento\Framework\Encryption\Encryptor::class);
102112
}
103113

104114
/**
105-
* Get config value by path.
115+
* Get configuration value by path
106116
*
107117
* System configuration is separated by scopes (default, websites, stores). Configuration of a scope is inherited
108118
* from its parent scope (store inherits website).
@@ -124,40 +134,14 @@ public function __construct(
124134
public function get($path = '')
125135
{
126136
if ($path === '') {
127-
$this->data = array_replace_recursive($this->data, $this->loadAllData());
137+
$this->data = array_replace_recursive($this->loadAllData(), $this->data);
128138

129139
return $this->data;
130140
}
131141

132142
return $this->getWithParts($path);
133143
}
134144

135-
/**
136-
* Merge newly loaded config data into already loaded.
137-
*
138-
* @param array $newData
139-
* @return void
140-
*/
141-
private function mergeData(array $newData): void
142-
{
143-
if (array_key_exists(ScopeInterface::SCOPE_DEFAULT, $newData)) {
144-
//Sometimes new data may contain links to arrays and we don't want that.
145-
$this->data[ScopeInterface::SCOPE_DEFAULT] = (array)$newData[ScopeInterface::SCOPE_DEFAULT];
146-
unset($newData[ScopeInterface::SCOPE_DEFAULT]);
147-
}
148-
foreach ($newData as $scopeType => $scopeTypeData) {
149-
if (!array_key_exists($scopeType, $this->data)) {
150-
//Sometimes new data may contain links to arrays and we don't want that.
151-
$this->data[$scopeType] = (array)$scopeTypeData;
152-
} else {
153-
foreach ($scopeTypeData as $scopeId => $scopeData) {
154-
//Sometimes new data may contain links to arrays and we don't want that.
155-
$this->data[$scopeType][$scopeId] = (array)$scopeData;
156-
}
157-
}
158-
}
159-
}
160-
161145
/**
162146
* Proceed with parts extraction from path.
163147
*
@@ -170,10 +154,8 @@ private function getWithParts($path)
170154

171155
if (count($pathParts) === 1 && $pathParts[0] !== ScopeInterface::SCOPE_DEFAULT) {
172156
if (!isset($this->data[$pathParts[0]])) {
173-
//First filling data property with unprocessed data for post-processors to be able to use.
174157
$data = $this->readData();
175-
//Post-processing only the data we know is not yet processed.
176-
$this->mergeData($this->postProcessor->process($data));
158+
$this->data = array_replace_recursive($data, $this->data);
177159
}
178160

179161
return $this->data[$pathParts[0]];
@@ -183,11 +165,7 @@ private function getWithParts($path)
183165

184166
if ($scopeType === ScopeInterface::SCOPE_DEFAULT) {
185167
if (!isset($this->data[$scopeType])) {
186-
//Adding unprocessed data to the data property so it can be used in post-processing.
187-
$this->mergeData($scopeData = $this->loadDefaultScopeData($scopeType));
188-
//Only post-processing the data we know is raw.
189-
$scopeData = $this->postProcessor->process($scopeData);
190-
$this->mergeData($scopeData);
168+
$this->data = array_replace_recursive($this->loadDefaultScopeData($scopeType), $this->data);
191169
}
192170

193171
return $this->getDataByPathParts($this->data[$scopeType], $pathParts);
@@ -197,11 +175,10 @@ private function getWithParts($path)
197175

198176
if (!isset($this->data[$scopeType][$scopeId])) {
199177
$scopeData = $this->loadScopeData($scopeType, $scopeId);
200-
//Adding unprocessed data to the data property so it can be used in post-processing.
201-
$this->mergeData($scopeData);
202-
//Only post-processing the data we know is raw.
203-
$scopeData = $this->postProcessor->process($scopeData);
204-
$this->mergeData($scopeData);
178+
179+
if (!isset($this->data[$scopeType][$scopeId])) {
180+
$this->data = array_replace_recursive($scopeData, $this->data);
181+
}
205182
}
206183

207184
return isset($this->data[$scopeType][$scopeId])
@@ -221,11 +198,10 @@ private function loadAllData()
221198
if ($cachedData === false) {
222199
$data = $this->readData();
223200
} else {
224-
$data = $this->serializer->unserialize($cachedData);
225-
$this->data = $data;
201+
$data = $this->serializer->unserialize($this->encryptor->decrypt($cachedData));
226202
}
227203

228-
return $this->postProcessor->process($data);
204+
return $data;
229205
}
230206

231207
/**
@@ -242,7 +218,7 @@ private function loadDefaultScopeData($scopeType)
242218
$data = $this->readData();
243219
$this->cacheData($data);
244220
} else {
245-
$data = [$scopeType => $this->serializer->unserialize($cachedData)];
221+
$data = [$scopeType => $this->serializer->unserialize($this->encryptor->decrypt($cachedData))];
246222
}
247223

248224
return $data;
@@ -263,7 +239,8 @@ private function loadScopeData($scopeType, $scopeId)
263239
if ($this->availableDataScopes === null) {
264240
$cachedScopeData = $this->cache->load($this->configType . '_scopes');
265241
if ($cachedScopeData !== false) {
266-
$this->availableDataScopes = $this->serializer->unserialize($cachedScopeData);
242+
$serializedCachedData = $this->encryptor->decrypt($cachedScopeData);
243+
$this->availableDataScopes = $this->serializer->unserialize($serializedCachedData);
267244
}
268245
}
269246
if (is_array($this->availableDataScopes) && !isset($this->availableDataScopes[$scopeType][$scopeId])) {
@@ -272,14 +249,15 @@ private function loadScopeData($scopeType, $scopeId)
272249
$data = $this->readData();
273250
$this->cacheData($data);
274251
} else {
275-
$data = [$scopeType => [$scopeId => $this->serializer->unserialize($cachedData)]];
252+
$serializedCachedData = $this->encryptor->decrypt($cachedData);
253+
$data = [$scopeType => [$scopeId => $this->serializer->unserialize($serializedCachedData)]];
276254
}
277255

278256
return $data;
279257
}
280258

281259
/**
282-
* Cache configuration data.
260+
* Cache configuration data
283261
*
284262
* Caches data per scope to avoid reading data for all scopes on every request
285263
*
@@ -289,12 +267,12 @@ private function loadScopeData($scopeType, $scopeId)
289267
private function cacheData(array $data)
290268
{
291269
$this->cache->save(
292-
$this->serializer->serialize($data),
270+
$this->encryptor->encryptWithFastestAvailableAlgorithm($this->serializer->serialize($data)),
293271
$this->configType,
294272
[self::CACHE_TAG]
295273
);
296274
$this->cache->save(
297-
$this->serializer->serialize($data['default']),
275+
$this->encryptor->encryptWithFastestAvailableAlgorithm($this->serializer->serialize($data['default'])),
298276
$this->configType . '_default',
299277
[self::CACHE_TAG]
300278
);
@@ -303,14 +281,14 @@ private function cacheData(array $data)
303281
foreach ($data[$curScopeType] ?? [] as $curScopeId => $curScopeData) {
304282
$scopes[$curScopeType][$curScopeId] = 1;
305283
$this->cache->save(
306-
$this->serializer->serialize($curScopeData),
284+
$this->encryptor->encryptWithFastestAvailableAlgorithm($this->serializer->serialize($curScopeData)),
307285
$this->configType . '_' . $curScopeType . '_' . $curScopeId,
308286
[self::CACHE_TAG]
309287
);
310288
}
311289
}
312290
$this->cache->save(
313-
$this->serializer->serialize($scopes),
291+
$this->encryptor->encryptWithFastestAvailableAlgorithm($this->serializer->serialize($scopes)),
314292
$this->configType . '_scopes',
315293
[self::CACHE_TAG]
316294
);
@@ -346,6 +324,9 @@ private function getDataByPathParts($data, $pathParts)
346324
private function readData(): array
347325
{
348326
$this->data = $this->reader->read();
327+
$this->data = $this->postProcessor->process(
328+
$this->data
329+
);
349330

350331
return $this->data;
351332
}

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable/Product/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected function _construct()
4141

4242
/**
4343
* Init select
44+
*
4445
* @return $this|\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
4546
*/
4647
protected function _initSelect()
@@ -73,9 +74,9 @@ public function setProductFilter($product)
7374
*
7475
* @return $this
7576
*/
76-
protected function _beforeLoad()
77+
protected function _renderFilters()
7778
{
78-
parent::_beforeLoad();
79+
parent::_renderFilters();
7980
$metadata = $this->getProductEntityMetadata();
8081
$parentIds = [];
8182
foreach ($this->products as $product) {
@@ -88,8 +89,7 @@ protected function _beforeLoad()
8889
}
8990

9091
/**
91-
* Retrieve is flat enabled flag
92-
* Return always false if magento run admin
92+
* Retrieve is flat enabled flag. Return always false if magento run admin
9393
*
9494
* @return bool
9595
*/

app/code/Magento/Variable/Model/Source/Variables.php

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ class Variables implements \Magento\Framework\Option\ArrayInterface
2323
*/
2424
private $configVariables = [];
2525

26+
/**
27+
* @var array
28+
*/
29+
private $configPaths = [];
30+
31+
/**
32+
* @var \Magento\Config\Model\Config\Structure\SearchInterface
33+
*/
34+
private $configStructure;
35+
2636
/**
2737
* Constructor.
2838
*
@@ -33,25 +43,8 @@ public function __construct(
3343
\Magento\Config\Model\Config\Structure\SearchInterface $configStructure,
3444
array $configPaths = []
3545
) {
36-
foreach ($configPaths as $groupPath => $groupElements) {
37-
$groupPathElements = explode('/', $groupPath);
38-
$path = [];
39-
$labels = [];
40-
foreach ($groupPathElements as $groupPathElement) {
41-
$path[] = $groupPathElement;
42-
$labels[] = __(
43-
$configStructure->getElementByConfigPath(implode('/', $path))->getLabel()
44-
);
45-
}
46-
$this->configVariables[$groupPath]['label'] = implode(' / ', $labels);
47-
foreach (array_keys($groupElements) as $elementPath) {
48-
$this->configVariables[$groupPath]['elements'][] = [
49-
'value' => $elementPath,
50-
'label' => __($configStructure->getElementByConfigPath($elementPath)->getLabel()),
51-
];
52-
}
53-
}
54-
$this->configVariables;
46+
$this->configStructure = $configStructure;
47+
$this->configPaths = $configPaths;
5548
}
5649

5750
/**
@@ -64,7 +57,7 @@ public function toOptionArray($withGroup = false)
6457
{
6558
$optionArray = [];
6659
if ($withGroup) {
67-
foreach ($this->configVariables as $configVariableGroup) {
60+
foreach ($this->getConfigVariables() as $configVariableGroup) {
6861
$group = [
6962
'label' => $configVariableGroup['label']
7063
];
@@ -79,7 +72,7 @@ public function toOptionArray($withGroup = false)
7972
$optionArray[] = $group;
8073
}
8174
} else {
82-
foreach ($this->configVariables as $configVariableGroup) {
75+
foreach ($this->getConfigVariables() as $configVariableGroup) {
8376
foreach ($configVariableGroup['elements'] as $element) {
8477
$optionArray[] = [
8578
'value' => '{{config path="' . $element['value'] . '"}}',
@@ -110,12 +103,43 @@ public function getData()
110103
private function getFlatConfigVars()
111104
{
112105
$result = [];
113-
foreach ($this->configVariables as $configVariableGroup) {
106+
foreach ($this->getConfigVariables() as $configVariableGroup) {
114107
foreach ($configVariableGroup['elements'] as $element) {
115108
$element['group_label'] = $configVariableGroup['label'];
116109
$result[] = $element;
117110
}
118111
}
119112
return $result;
120113
}
114+
115+
/**
116+
* Merge config with user defined data
117+
*
118+
* @return array
119+
*/
120+
private function getConfigVariables()
121+
{
122+
if (empty($this->configVariables)) {
123+
foreach ($this->configPaths as $groupPath => $groupElements) {
124+
$groupPathElements = explode('/', $groupPath);
125+
$path = [];
126+
$labels = [];
127+
foreach ($groupPathElements as $groupPathElement) {
128+
$path[] = $groupPathElement;
129+
$labels[] = __(
130+
$this->configStructure->getElementByConfigPath(implode('/', $path))->getLabel()
131+
);
132+
}
133+
$this->configVariables[$groupPath]['label'] = implode(' / ', $labels);
134+
foreach (array_keys($groupElements) as $elementPath) {
135+
$this->configVariables[$groupPath]['elements'][] = [
136+
'value' => $elementPath,
137+
'label' => __($this->configStructure->getElementByConfigPath($elementPath)->getLabel()),
138+
];
139+
}
140+
}
141+
}
142+
143+
return $this->configVariables;
144+
}
121145
}

0 commit comments

Comments
 (0)