Skip to content

Commit

Permalink
Merge pull request #1937 from magento-engcom/MSI-1921-performance-deg…
Browse files Browse the repository at this point in the history
…radation-on-the-catalog-page

MSI-1921: Removed redundant join on 'catalog_product_entity'
  • Loading branch information
maghamed authored Dec 14, 2018
2 parents 5b2d05a + c515c2c commit 26c7e65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ApplyStockConditionToSelect;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Select;
use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface;
use Magento\InventoryIndexer\Indexer\IndexStructure;
use Magento\InventoryIndexer\Model\StockIndexTableNameResolver;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
Expand Down Expand Up @@ -42,22 +43,30 @@ class AdaptApplyStockConditionToSelectPlugin
*/
private $stockResolver;

/**
* @var DefaultStockProviderInterface
*/
private $defaultStockProvider;

/**
* @param StockIndexTableNameResolver $stockIndexTableNameResolver
* @param ResourceConnection $resource
* @param StoreManagerInterface $storeManager
* @param StockResolverInterface $stockResolver
* @param DefaultStockProviderInterface $defaultStockProvider
*/
public function __construct(
StockIndexTableNameResolver $stockIndexTableNameResolver,
ResourceConnection $resource,
StoreManagerInterface $storeManager,
StockResolverInterface $stockResolver
StockResolverInterface $stockResolver,
DefaultStockProviderInterface $defaultStockProvider
) {
$this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
$this->resource = $resource;
$this->storeManager = $storeManager;
$this->stockResolver = $stockResolver;
$this->defaultStockProvider = $defaultStockProvider;
}

/**
Expand All @@ -77,6 +86,10 @@ public function aroundExecute(
$stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode);
$stockId = (int)$stock->getStockId();

if ($stockId === $this->defaultStockProvider->getId()) {
return $proceed($select);
}

$tableName = $this->stockIndexTableNameResolver->execute($stockId);
$select->joinInner(
['product' => $this->resource->getTableName('catalog_product_entity')],
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/InventoryCatalogSearch/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"magento/framework": "*",
"magento/module-inventory-sales-api": "*",
"magento/module-inventory-indexer": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-store": "*"
},
"suggest": {
Expand Down

0 comments on commit 26c7e65

Please sign in to comment.