Skip to content

Commit 57fb307

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-70303' into EPAM-PR-16
2 parents e47739d + ea66105 commit 57fb307

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ abstract class AbstractAction
123123
*/
124124
private $queryGenerator;
125125

126+
/**
127+
* @var int
128+
*/
129+
private $currentStoreId = 0;
130+
126131
/**
127132
* @param ResourceConnection $resource
128133
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -164,6 +169,7 @@ protected function reindex()
164169
{
165170
foreach ($this->storeManager->getStores() as $store) {
166171
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
172+
$this->currentStoreId = $store->getId();
167173
$this->reindexRootCategory($store);
168174
$this->reindexAnchorCategories($store);
169175
$this->reindexNonAnchorCategories($store);
@@ -586,6 +592,8 @@ protected function createAnchorSelect(Store $store)
586592
}
587593

588594
/**
595+
* Get temporary table name
596+
*
589597
* Get temporary table name for concurrent indexing in persistent connection
590598
* Temp table name is NOT shared between action instances and each action has it's own temp tree index
591599
*
@@ -597,7 +605,7 @@ protected function getTemporaryTreeIndexTableName()
597605
if (empty($this->tempTreeIndexTableName)) {
598606
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
599607
. '_'
600-
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
608+
. substr(sha1(time() . random_int(0, 999999999)), 0, 8);
601609
}
602610

603611
return $this->tempTreeIndexTableName;
@@ -641,7 +649,6 @@ protected function makeTempCategoryTreeIndex()
641649
['child_id'],
642650
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
643651
);
644-
645652
// Drop the temporary table in case it already exists on this (persistent?) connection.
646653
$this->connection->dropTemporaryTable($temporaryName);
647654
$this->connection->createTemporaryTable($temporaryTable);
@@ -659,11 +666,31 @@ protected function makeTempCategoryTreeIndex()
659666
*/
660667
protected function fillTempCategoryTreeIndex($temporaryName)
661668
{
669+
$isActiveAttributeId = $this->config->getAttribute(
670+
\Magento\Catalog\Model\Category::ENTITY,
671+
'is_active'
672+
)->getId();
673+
$categoryMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
674+
$categoryLinkField = $categoryMetadata->getLinkField();
662675
$selects = $this->prepareSelectsByRange(
663676
$this->connection->select()
664677
->from(
665678
['c' => $this->getTable('catalog_category_entity')],
666679
['entity_id', 'path']
680+
)->joinInner(
681+
['ccacd' => $this->getTable('catalog_category_entity_int')],
682+
'ccacd.' . $categoryLinkField . ' = c.' . $categoryLinkField . ' AND ccacd.store_id = 0' .
683+
' AND ccacd.attribute_id = ' . $isActiveAttributeId,
684+
[]
685+
)->joinLeft(
686+
['ccacs' => $this->getTable('catalog_category_entity_int')],
687+
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
688+
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
689+
$this->currentStoreId,
690+
[]
691+
)->where(
692+
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
693+
1
667694
),
668695
'entity_id'
669696
);

0 commit comments

Comments
 (0)