Skip to content

Commit ae0933c

Browse files
MAGETWO-92693: Some improvements on product create|edit page in admin area
1 parent b457120 commit ae0933c

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ public function _loadAttributes($printQuery = false, $logQuery = false)
11751175
$attributeTypes[$table]
11761176
);
11771177
}
1178-
$selectGroups = $this->_resourceHelper->mergeToOneGroup($selects);
1178+
$selectGroups = $this->_resourceHelper->getLoadAttributesSelectGroups($selects);
11791179
foreach ($selectGroups as $selects) {
11801180
if (!empty($selects)) {
11811181
try {

app/code/Magento/Eav/Model/ResourceModel/Helper.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ public function __construct(\Magento\Framework\App\ResourceConnection $resource,
4646
\Magento\Framework\DB\Ddl\Table::TYPE_VARBINARY => 'blob',
4747
];
4848

49+
/**
50+
* Attribute types that can be united via UNION into one query
51+
* while selecting attribute`s data from tables like `catalog_product_entity_datatype`
52+
*
53+
* This helps to run one query with all data types instead of one per each data type
54+
*
55+
* This data types are determined as 'groupable' because their tables have the same structure
56+
* which means that they can be used in one UNION query
57+
*
58+
* @var array
59+
*/
60+
private $_groupableTypes = ['varchar', 'text', 'decimal', 'datetime', 'int'];
61+
4962
/**
5063
* Returns DDL type by column type in database
5164
*
@@ -72,20 +85,41 @@ public function getDdlTypeByColumnType($columnType)
7285
/**
7386
* Groups selects to separate unions depend on type
7487
*
88+
* E.g. for input array:
89+
* [
90+
* varchar => [select1, select2],
91+
* text => [select3],
92+
* int => [select4],
93+
* bool => [select5]
94+
* ]
95+
*
96+
* The result array will be:
97+
* [
98+
* 0 => [select1, select2, select3, select4] // contains queries for varchar & text & int
99+
* 1 => [select5] // contains queries for bool
100+
* ]
101+
*
75102
* @param array $selects
76103
* @return array
77104
*/
78105
public function getLoadAttributesSelectGroups($selects)
79106
{
80107
$mainGroup = [];
81-
foreach ($selects as $selectGroup) {
82-
$mainGroup = array_merge($mainGroup, $selectGroup);
108+
109+
foreach ($selects as $dataType => $selectGroup) {
110+
if (in_array($dataType, $this->_groupableTypes)) {
111+
$mainGroup['all'][] = $selectGroup;
112+
continue;
113+
}
114+
115+
$mainGroup[$dataType] = $selectGroup;
83116
}
84-
return $mainGroup;
85-
}
86117

87-
public function mergeToOneGroup($selects)
88-
{
89-
return [$this->getLoadAttributesSelectGroups($selects)];
118+
if (array_key_exists('all', $mainGroup)) {
119+
// it is better to call array_merge once after loop instead of calling it on each loop
120+
$mainGroup['all'] = array_merge(...$mainGroup['all']);
121+
}
122+
123+
return array_values($mainGroup);
90124
}
91125
}

0 commit comments

Comments
 (0)