Skip to content

Commit 40a0123

Browse files
committed
MAGETWO-48790: Reindex hanging after large import of products
1 parent ecd3cb5 commit 40a0123

File tree

3 files changed

+21
-61
lines changed

3 files changed

+21
-61
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class Product extends AbstractResource
6666
*/
6767
protected $defaultAttributes;
6868

69+
/**
70+
* @var array
71+
*/
72+
protected $availableCategoryIdsCache = [];
73+
6974
/**
7075
* @param \Magento\Eav\Model\Entity\Context $context
7176
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -465,18 +470,22 @@ public function getAvailableInCategories($object)
465470
{
466471
// is_parent=1 ensures that we'll get only category IDs those are direct parents of the product, instead of
467472
// fetching all parent IDs, including those are higher on the tree
468-
$select = $this->getConnection()->select()->distinct()->from(
469-
$this->getTable('catalog_category_product_index'),
470-
['category_id']
471-
)->where(
472-
'product_id = ? AND is_parent = 1',
473-
(int)$object->getEntityId()
474-
)->where(
475-
'visibility != ?',
476-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
477-
);
478-
479-
return $this->getConnection()->fetchCol($select);
473+
$entityId = (int)$object->getEntityId();
474+
if (!isset($this->availableCategoryIdsCache[$entityId])) {
475+
$this->availableCategoryIdsCache[$entityId] = $this->getConnection()->fetchCol(
476+
$this->getConnection()->select()->distinct()->from(
477+
$this->getTable('catalog_category_product_index'),
478+
['category_id']
479+
)->where(
480+
'product_id = ? AND is_parent = 1',
481+
$entityId
482+
)->where(
483+
'visibility != ?',
484+
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
485+
)
486+
);
487+
}
488+
return $this->availableCategoryIdsCache[$entityId];
480489
}
481490

482491
/**

app/code/Magento/Rule/Plugin/Catalog/Model/Product.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/code/Magento/Rule/etc/adminhtml/di.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)