Skip to content

Commit 7015076

Browse files
ACPT-978: Improve Config Save filtering
This performance improvement is in Save and Structure and totals to ~42x improvement in Magento\Config\Controller\Adminhtml\System\Config\Save::filterNodes
1 parent d4680f1 commit 7015076

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,11 @@ private function filterPaths(string $prefix, array $groups, array $systemXmlConf
335335
private function filterNodes(array $configData): array
336336
{
337337
if (!empty($configData['groups'])) {
338-
$systemXmlPathsFromKeys = array_keys($this->_configStructure->getFieldPaths());
339-
$systemXmlPathsFromValues = array_reduce(
340-
array_values($this->_configStructure->getFieldPaths()),
341-
'array_merge',
342-
[]
343-
);
344338
//Full list of paths defined in system.xml
345-
$systemXmlConfig = array_merge($systemXmlPathsFromKeys, $systemXmlPathsFromValues);
346-
339+
$fieldPaths = $this->_configStructure->getFieldPaths();
340+
$systemXmlConfig = array_merge(array_keys($fieldPaths), ...array_values($fieldPaths));
347341
$configData['groups'] = $this->filterPaths($configData['section'], $configData['groups'], $systemXmlConfig);
348342
}
349-
350343
return $configData;
351344
}
352345
}

app/code/Magento/Config/Model/Config/Structure.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,32 +384,22 @@ public function getFieldPaths()
384384
* Iteration that collects config field paths recursively from config files.
385385
*
386386
* @param array $elements The elements to be parsed
387+
* @param array $result used for recursive calls
387388
* @return array An array of config path to config structure path map
388389
*/
389-
private function getFieldsRecursively(array $elements = [])
390+
private function getFieldsRecursively(array $elements = [], &$result = [])
390391
{
391-
$result = [];
392-
393392
foreach ($elements as $element) {
394393
if (isset($element['children'])) {
395-
$result = array_merge_recursive(
396-
$result,
397-
$this->getFieldsRecursively($element['children'])
398-
);
394+
$this->getFieldsRecursively($element['children'], $result);
399395
} else {
400396
if ($element['_elementType'] === 'field') {
401397
$structurePath = (isset($element['path']) ? $element['path'] . '/' : '') . $element['id'];
402398
$configPath = isset($element['config_path']) ? $element['config_path'] : $structurePath;
403-
404-
if (!isset($result[$configPath])) {
405-
$result[$configPath] = [];
406-
}
407-
408399
$result[$configPath][] = $structurePath;
409400
}
410401
}
411402
}
412-
413403
return $result;
414404
}
415405
}

0 commit comments

Comments
 (0)