Skip to content

Commit b1ce314

Browse files
authored
Merge pull request #3047 from magento-performance/MAGETWO-93753
[performance] MAGETWO-93753: [Forwardport] Implement sharding and parallelization for Price Indexer
2 parents 232eec2 + e2b3398 commit b1ce314

File tree

49 files changed

+3505
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3505
-600
lines changed

app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
1717
use Magento\Framework\Search\Request\IndexScopeResolverInterface as TableResolver;
1818
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
19+
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1920

2021
/**
2122
* @api
@@ -47,12 +48,17 @@ class Index extends AbstractDb
4748
*/
4849
private $dimensionCollectionFactory;
4950

51+
/**
52+
* @var int|null
53+
*/
54+
private $websiteId;
55+
5056
/**
5157
* Index constructor.
5258
* @param Context $context
5359
* @param StoreManagerInterface $storeManager
5460
* @param MetadataPool $metadataPool
55-
* @param null $connectionName
61+
* @param string|null $connectionName
5662
* @param TableResolver|null $tableResolver
5763
* @param DimensionCollectionFactory|null $dimensionCollectionFactory
5864
*/
@@ -94,12 +100,17 @@ protected function _getCatalogProductPriceData($productIds = null)
94100
$catalogProductIndexPriceSelect = [];
95101

96102
foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
97-
$catalogProductIndexPriceSelect[] = $connection->select()->from(
98-
$this->tableResolver->resolve('catalog_product_index_price', $dimensions),
99-
['entity_id', 'customer_group_id', 'website_id', 'min_price']
100-
);
101-
if ($productIds) {
102-
current($catalogProductIndexPriceSelect)->where('entity_id IN (?)', $productIds);
103+
if (!isset($dimensions[WebsiteDimensionProvider::DIMENSION_NAME]) ||
104+
$this->websiteId === null ||
105+
$dimensions[WebsiteDimensionProvider::DIMENSION_NAME]->getValue() === $this->websiteId) {
106+
$select = $connection->select()->from(
107+
$this->tableResolver->resolve('catalog_product_index_price', $dimensions),
108+
['entity_id', 'customer_group_id', 'website_id', 'min_price']
109+
);
110+
if ($productIds) {
111+
$select->where('entity_id IN (?)', $productIds);
112+
}
113+
$catalogProductIndexPriceSelect[] = $select;
103114
}
104115
}
105116

@@ -123,9 +134,12 @@ protected function _getCatalogProductPriceData($productIds = null)
123134
*/
124135
public function getPriceIndexData($productIds, $storeId)
125136
{
137+
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
138+
139+
$this->websiteId = $websiteId;
126140
$priceProductsIndexData = $this->_getCatalogProductPriceData($productIds);
141+
$this->websiteId = null;
127142

128-
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
129143
if (!isset($priceProductsIndexData[$websiteId])) {
130144
return [];
131145
}

0 commit comments

Comments
 (0)