Skip to content

Commit 4d871db

Browse files
MAGETWO-69130: Non effective query for catalog search & layered navigation
1 parent d8513ec commit 4d871db

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/BundleOptionStockDataSelectBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildSelect($idxTable)
5757
[]
5858
)->group(
5959
['product.entity_id', 'cis.website_id', 'cis.stock_id', 'bo.option_id']
60-
)->columns(['option_id' => 'bo.option_id','status' => new \Zend_Db_Expr('MAX('. $statusExpression. ')')]);
60+
)->columns(['option_id' => 'bo.option_id']);
6161

6262
return $select;
6363
}

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\
4040
* @param string $connectionName
4141
* @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory
4242
* @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource
43-
* @param null|\Magento\Bundle\Model\ResourceModel\Indexer\StockStatusSelectBuilder $stockStatusSelectBuilder
43+
* @param null|StockStatusSelectBuilder $stockStatusSelectBuilder
44+
* @param null|BundleOptionStockDataSelectBuilder $bundleOptionStockDataSelectBuilder
4445
*/
4546
public function __construct(
4647
\Magento\Framework\Model\ResourceModel\Db\Context $context,

app/code/Magento/Bundle/Model/ResourceModel/Indexer/StockStatusSelectBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct(
3131
/**
3232
* @param Select $select
3333
* @return Select
34+
* @throws \Exception
3435
*/
3536
public function buildSelect(Select $select)
3637
{
@@ -39,7 +40,7 @@ public function buildSelect(Select $select)
3940
$linkField = $metadata->getLinkField();
4041

4142
$select->reset(
42-
\Magento\Framework\DB\Select::COLUMNS
43+
Select::COLUMNS
4344
)->columns(
4445
['e.entity_id', 'cis.website_id', 'cis.stock_id']
4546
)->joinLeft(

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,24 @@ protected function _deleteOldRelations($tableName)
230230

231231
/**
232232
* Delete records by their ids from index table
233-
* Is used to clean table before re-indexation
233+
* Used to clean table before re-indexation
234234
*
235235
* @param array $ids
236-
*
237-
* @return bool
236+
* @return void
238237
*/
239238
protected function _deleteOldRecords(array $ids)
240239
{
241-
if (count($ids) === 0) {
242-
return false;
240+
if (count($ids) !== 0) {
241+
$this->_getConnection()->delete(
242+
$this->indexerStockFrontendResource->getMainTable(),
243+
['product_id in (?)' => $ids]
244+
);
243245
}
244-
245-
$result = $this->_getConnection()->delete(
246-
$this->indexerStockFrontendResource->getMainTable(),
247-
['product_id in (?)' => $ids]
248-
);
249-
250-
return (bool) $result;
251246
}
252247

253248
/**
254249
* Delete all records from index table
255-
* Is used to clean table before re-indexation
250+
* Used to clean table before re-indexation
256251
*
257252
* @return void
258253
*/

app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function clean(array $productIds, callable $reindex)
8484
$productStatusesBefore = $this->getProductStockStatuses($productIds);
8585
$reindex();
8686
$productStatusesAfter = $this->getProductStockStatuses($productIds);
87-
$productIds = $this->getProductIds($productStatusesBefore, $productStatusesAfter);
87+
$productIds = $this->getProductIdsForCacheClean($productStatusesBefore, $productStatusesAfter);
8888
if ($productIds) {
8989
$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
9090
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
@@ -113,11 +113,13 @@ private function getProductStockStatuses(array $productIds)
113113
}
114114

115115
/**
116+
* Return list of product ids that need to be flushed from cache
117+
*
116118
* @param array $productStatusesBefore
117119
* @param array $productStatusesAfter
118120
* @return array
119121
*/
120-
private function getProductIds(array $productStatusesBefore, array $productStatusesAfter)
122+
private function getProductIdsForCacheClean(array $productStatusesBefore, array $productStatusesAfter)
121123
{
122124
$disabledProductsIds = array_diff(array_keys($productStatusesBefore), array_keys($productStatusesAfter));
123125
$enabledProductsIds = array_diff(array_keys($productStatusesAfter), array_keys($productStatusesBefore));

0 commit comments

Comments
 (0)