Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 9f0584a

Browse files
Freek VandeursenFreek Vandeursen
Freek Vandeursen
authored and
Freek Vandeursen
committed
Improve attribute checking
On a store with a large number of attribute sets, a lot of repeated checking is done for the same attributes. So instead we can keep track of the attributes we already checked, and skip them the next time.
1 parent ce5eacd commit 9f0584a

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ abstract class AbstractType
2828
*/
2929
public static $commonAttributesCache = [];
3030

31+
/**
32+
* Maintain a list of invisible attributes
33+
*
34+
* @var array
35+
*/
36+
public static $invisibleAttributesCache = [];
37+
3138
/**
3239
* Attribute Code to Id cache
3340
*
@@ -278,7 +285,10 @@ protected function _initAttributes()
278285
}
279286
}
280287
foreach ($absentKeys as $attributeSetName => $attributeIds) {
281-
$this->attachAttributesById($attributeSetName, $attributeIds);
288+
$unknownAttributeIds = array_diff($attributeIds, array_keys(self::$commonAttributesCache), self::$invisibleAttributesCache);
289+
if ($unknownAttributeIds) {
290+
$this->attachAttributesById($attributeSetName, $attributeIds);
291+
}
282292
}
283293
foreach ($entityAttributes as $attributeRow) {
284294
if (isset(self::$commonAttributesCache[$attributeRow['attribute_id']])) {
@@ -310,30 +320,35 @@ protected function attachAttributesById($attributeSetName, $attributeIds)
310320
$attributeId = $attribute->getId();
311321

312322
if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
313-
self::$commonAttributesCache[$attributeId] = [
314-
'id' => $attributeId,
315-
'code' => $attributeCode,
316-
'is_global' => $attribute->getIsGlobal(),
317-
'is_required' => $attribute->getIsRequired(),
318-
'is_unique' => $attribute->getIsUnique(),
319-
'frontend_label' => $attribute->getFrontendLabel(),
320-
'is_static' => $attribute->isStatic(),
321-
'apply_to' => $attribute->getApplyTo(),
322-
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
323-
'default_value' => strlen(
324-
$attribute->getDefaultValue()
325-
) ? $attribute->getDefaultValue() : null,
326-
'options' => $this->_entityModel->getAttributeOptions(
327-
$attribute,
328-
$this->_indexValueAttributes
329-
),
330-
];
323+
if (!isset(self::$commonAttributesCache[$attributeId])) {
324+
self::$commonAttributesCache[$attributeId] = [
325+
'id' => $attributeId,
326+
'code' => $attributeCode,
327+
'is_global' => $attribute->getIsGlobal(),
328+
'is_required' => $attribute->getIsRequired(),
329+
'is_unique' => $attribute->getIsUnique(),
330+
'frontend_label' => $attribute->getFrontendLabel(),
331+
'is_static' => $attribute->isStatic(),
332+
'apply_to' => $attribute->getApplyTo(),
333+
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
334+
'default_value' => strlen(
335+
$attribute->getDefaultValue()
336+
) ? $attribute->getDefaultValue() : null,
337+
'options' => $this->_entityModel->getAttributeOptions(
338+
$attribute,
339+
$this->_indexValueAttributes
340+
),
341+
];
342+
}
343+
331344
self::$attributeCodeToId[$attributeCode] = $attributeId;
332345
$this->_addAttributeParams(
333346
$attributeSetName,
334347
self::$commonAttributesCache[$attributeId],
335348
$attribute
336349
);
350+
} else {
351+
self::$invisibleAttributesCache[] = $attributeId;
337352
}
338353
}
339354
}

0 commit comments

Comments
 (0)