Skip to content

Commit d54d446

Browse files
author
Michail Slabko
committed
MAGETWO-47877: Product Import (HUGE SQL statements/slow) #2957
1 parent 7dc2155 commit d54d446

File tree

1 file changed

+18
-16
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+18
-16
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ public function __construct(
745745
->_initTypeModels()
746746
->_initSkus();
747747
$this->validator->init($this);
748-
$this->initMediaGalleryResources();
749748
}
750749

751750
/**
@@ -1292,15 +1291,19 @@ public function saveProductEntity(array $entityRowsIn, array $entityRowsUp)
12921291
*/
12931292
protected function initMediaGalleryResources()
12941293
{
1295-
$this->productEntityTableName = $this->getResource()->getTable('catalog_product_entity');
1296-
$this->mediaGalleryTableName = $this->getResource()->getTable('catalog_product_entity_media_gallery');
1297-
$this->mediaGalleryValueTableName = $this->getResource()->getTable('catalog_product_entity_media_gallery_value');
1298-
$this->mediaGalleryEntityToValueTableName = $this->getResource()->getTable(
1299-
'catalog_product_entity_media_gallery_value_to_entity'
1300-
);
1301-
$this->productEntityLinkField = $this->metadataPool
1302-
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
1303-
->getLinkField();
1294+
if (null == $this->mediaGalleryTableName) {
1295+
$this->productEntityTableName = $this->getResource()->getTable('catalog_product_entity');
1296+
$this->mediaGalleryTableName = $this->getResource()->getTable('catalog_product_entity_media_gallery');
1297+
$this->mediaGalleryValueTableName = $this->getResource()->getTable(
1298+
'catalog_product_entity_media_gallery_value'
1299+
);
1300+
$this->mediaGalleryEntityToValueTableName = $this->getResource()->getTable(
1301+
'catalog_product_entity_media_gallery_value_to_entity'
1302+
);
1303+
$this->productEntityLinkField = $this->metadataPool
1304+
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
1305+
->getLinkField();
1306+
}
13041307
}
13051308

13061309
/**
@@ -1312,21 +1315,19 @@ protected function initMediaGalleryResources()
13121315
protected function getExistingImages($bunch)
13131316
{
13141317
$result = [];
1315-
$productSKUs = array_map('strval', array_column($bunch, self::COL_SKU));
1316-
if (!$productSKUs) {
1318+
if ($this->getErrorAggregator()->hasToBeTerminated()) {
13171319
return $result;
13181320
}
13191321

1320-
$linkField = $this->metadataPool
1321-
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
1322-
->getLinkField();
1322+
$this->initMediaGalleryResources();
1323+
$productSKUs = array_map('strval', array_column($bunch, self::COL_SKU));
13231324
$select = $this->_connection->select()->from(
13241325
['mg' => $this->mediaGalleryTableName],
13251326
['value' => 'mg.value']
13261327
)->joinInner(
13271328
['mgvte' => $this->mediaGalleryEntityToValueTableName],
13281329
'(mg.value_id = mgvte.value_id)',
1329-
[$linkField => 'mgvte.' . $linkField]
1330+
[$this->productEntityLinkField => 'mgvte.' . $this->productEntityLinkField]
13301331
)->joinInner(
13311332
['pe' => $this->productEntityTableName],
13321333
"(mgvte.{$this->productEntityLinkField} = pe.{$this->productEntityLinkField})",
@@ -1814,6 +1815,7 @@ protected function _saveMediaGallery(array $mediaGalleryData)
18141815
if (empty($mediaGalleryData)) {
18151816
return $this;
18161817
}
1818+
$this->initMediaGalleryResources();
18171819
$productIds = [];
18181820
$imageNames = [];
18191821
$multiInsertData = [];

0 commit comments

Comments
 (0)