Skip to content

Commit

Permalink
Performance Fix for Large Catalogs
Browse files Browse the repository at this point in the history
Refer to this thread for the full issue.
magento/magento2#278

We confirmed this issue Exists in Magento EE 1.13 Where for large
catalogs we were experiencing out of memory issues due to this function
_loadSkuSuperAttributeValues()

This patch will help those stores with large amounts of configurable
products process large imports with hundreds of thousands of rows
without hitting this issue as a
bottleneck
  • Loading branch information
Andy committed Nov 12, 2014
1 parent 1bbefc7 commit 1df432b
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,47 @@ protected function _isSkuNew($sku)
return !isset($oldSkus[$sku]);
}

/**
* Array of SKU to array of super attribute values for all products.
*
* @return Mage_ImportExport_Model_Import_Entity_Product_Type_Configurable
*/
protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku)
{
if ($this->_superAttributes) {
$attrSetIdToName = $this->_entityModel->getAttrSetIdToName();
$allowProductTypes = array();

foreach ($bunch as $rowData){
if (!empty($rowData['_super_products_sku'])) {
if (isset($newSku[$rowData['_super_products_sku']])) {
$productIdArray[] = $newSku[$rowData['_super_products_sku']];
} elseif (isset($oldSku[$rowData['_super_products_sku']])) {
$productIdArray[] = $oldSku[$rowData['_super_products_sku']];
}
}
}
foreach (Mage::getConfig()
->getNode('global/catalog/product/type/configurable/allow_product_types')->children() as $type) {
$allowProductTypes[] = $type->getName();
}
foreach (Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('type_id', $allowProductTypes)
->addFieldToFilter ('entity_id', array('in' => $productIdArray))
->addAttributeToSelect(array_keys($this->_superAttributes)) as $product) {
$attrSetName = $attrSetIdToName[$product->getAttributeSetId()];
$data = array_intersect_key(
$product->getData(),
$this->_superAttributes
);
foreach ($data as $attrCode => $value) {
$attrId = $this->_superAttributes[$attrCode]['id'];
$this->_skuSuperAttributeValues[$attrSetName][$product->getId()][$attrId] = $value;
}
}
}
return $this;
}

/**
* Save product type specific data.
Expand All @@ -149,7 +190,6 @@ public function saveData()
if ($this->_entityModel->getBehavior() == Mage_ImportExport_Model_Import::BEHAVIOR_APPEND) {
$this->_loadSkuSuperData();
}
$this->_loadSkuSuperAttributeValues();

while ($bunch = $this->_entityModel->getNextBunch()) {
$superAttributes = array(
Expand All @@ -159,6 +199,9 @@ public function saveData()
'super_link' => array(),
'relation' => array()
);

$this->_loadSkuSuperAttributeValues($bunch, $newSku, $oldSku);

foreach ($bunch as $rowNum => $rowData) {
if (!$this->_entityModel->isRowAllowedToImport($rowData, $rowNum)) {
continue;
Expand Down

0 comments on commit 1df432b

Please sign in to comment.