Skip to content

Commit a78e5f9

Browse files
committed
MAGETWO-92887: [Indexer optimizations] Tables sharding / segmentation for price indexer - part 2
- composite price modifier
1 parent 62a9f67 commit a78e5f9

File tree

10 files changed

+70
-87
lines changed

10 files changed

+70
-87
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
9+
10+
/**
11+
* Apply price modifiers to product price indexer which are common for all product types:
12+
* custom options, catalog rule, catalog inventory modifiers
13+
*/
14+
class BasePriceModifier implements PriceModifierInterface
15+
{
16+
/**
17+
* @var PriceModifierInterface[]
18+
*/
19+
private $priceModifiers;
20+
21+
/**
22+
* @param array $priceModifiers
23+
*/
24+
public function __construct(array $priceModifiers)
25+
{
26+
$this->priceModifiers = $priceModifiers;
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function modifyPrice(IndexTableStructure $priceTable, array $entityIds = [])
33+
{
34+
foreach ($this->priceModifiers as $priceModifier) {
35+
$priceModifier->modifyPrice($priceTable, $entityIds);
36+
}
37+
}
38+
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/SimpleProductPrice.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@ class SimpleProductPrice implements DimensionalIndexerInterface
3636
private $productType;
3737

3838
/**
39-
* @var PriceModifierInterface[]
39+
* @var BasePriceModifier
4040
*/
41-
private $priceModifiers;
41+
private $basePriceModifier;
4242

4343
/**
4444
* @param BaseFinalPrice $baseFinalPrice
4545
* @param IndexTableStructureFactory $indexTableStructureFactory
4646
* @param TableMaintainer $tableMaintainer
47+
* @param BasePriceModifier $basePriceModifier
4748
* @param string $productType
48-
* @param array $priceModifiers
4949
*/
5050
public function __construct(
5151
BaseFinalPrice $baseFinalPrice,
5252
IndexTableStructureFactory $indexTableStructureFactory,
5353
TableMaintainer $tableMaintainer,
54-
$productType = \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
55-
array $priceModifiers = []
54+
BasePriceModifier $basePriceModifier,
55+
$productType = \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
5656
) {
5757
$this->baseFinalPrice = $baseFinalPrice;
5858
$this->indexTableStructureFactory = $indexTableStructureFactory;
5959
$this->tableMaintainer = $tableMaintainer;
6060
$this->productType = $productType;
61-
$this->priceModifiers = $priceModifiers;
61+
$this->basePriceModifier = $basePriceModifier;
6262
}
6363

6464
/**
@@ -84,19 +84,6 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
8484
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);
8585
$this->tableMaintainer->getConnection()->query($query);
8686

87-
$this->applyPriceModifiers($temporaryPriceTable);
88-
}
89-
90-
/**
91-
* Apply price modifiers to temporary price index table
92-
*
93-
* @param IndexTableStructure $temporaryPriceTable
94-
* @return void
95-
*/
96-
private function applyPriceModifiers(IndexTableStructure $temporaryPriceTable)
97-
{
98-
foreach ($this->priceModifiers as $priceModifier) {
99-
$priceModifier->modifyPrice($temporaryPriceTable);
100-
}
87+
$this->basePriceModifier->modifyPrice($temporaryPriceTable, iterator_to_array($entityIds));
10188
}
10289
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@
11171117
<argument name="tableResolver" xsi:type="object">Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver</argument>
11181118
</arguments>
11191119
</type>
1120-
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\SimpleProductPrice">
1120+
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier">
11211121
<arguments>
11221122
<argument name="priceModifiers" xsi:type="array">
11231123
<item name="customOptionPriceModifier" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier</item>

app/code/Magento/CatalogInventory/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
</argument>
126126
</arguments>
127127
</type>
128-
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\SimpleProductPrice">
128+
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier">
129129
<arguments>
130130
<argument name="priceModifiers" xsi:type="array">
131131
<item name="inventoryProductPriceIndexFilter" xsi:type="object">Magento\CatalogInventory\Model\Indexer\ProductPriceIndexFilter</item>

app/code/Magento/CatalogRule/etc/di.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
</argument>
135135
</arguments>
136136
</type>
137-
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\SimpleProductPrice">
137+
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier">
138138
<arguments>
139139
<argument name="priceModifiers" xsi:type="array">
140140
<item name="catalogRulePriceModifier" xsi:type="object">Magento\CatalogRule\Model\Indexer\ProductPriceIndexModifier</item>
@@ -164,11 +164,4 @@
164164
<argument name="customConditionProvider" xsi:type="object">CatalogRuleCustomConditionProvider</argument>
165165
</arguments>
166166
</type>
167-
<type name="Magento\Downloadable\Model\ResourceModel\Indexer\Price">
168-
<arguments>
169-
<argument name="priceModifiers" xsi:type="array">
170-
<item name="catalogRulePriceModifier" xsi:type="object">Magento\CatalogRule\Model\Indexer\ProductPriceIndexModifier</item>
171-
</argument>
172-
</arguments>
173-
</type>
174167
</config>

app/code/Magento/CatalogRuleConfigurable/etc/di.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,4 @@
99
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection">
1010
<plugin name="catalogRulePriceForConfigurableProduct" type="Magento\CatalogRuleConfigurable\Plugin\ConfigurableProduct\Model\ResourceModel\AddCatalogRulePrice" />
1111
</type>
12-
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable">
13-
<arguments>
14-
<argument name="priceModifiers" xsi:type="array">
15-
<item name="catalogRulePriceModifier" xsi:type="object">Magento\CatalogRule\Model\Indexer\ProductPriceIndexModifier</item>
16-
</argument>
17-
</arguments>
18-
</type>
1912
</config>

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price;
77

8+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier;
89
use Magento\Framework\Indexer\DimensionalIndexerInterface;
910
use Magento\Framework\EntityManager\MetadataPool;
1011
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
1112
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPrice;
1213
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1314
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
14-
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
1515
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1616
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
1717

@@ -68,9 +68,9 @@ class Configurable implements DimensionalIndexerInterface
6868
private $productType;
6969

7070
/**
71-
* @var PriceModifierInterface[]
71+
* @var BasePriceModifier
7272
*/
73-
private $priceModifiers;
73+
private $basePriceModifier;
7474

7575
/**
7676
* @param BaseFinalPrice $baseFinalPrice
@@ -89,20 +89,20 @@ public function __construct(
8989
TableMaintainer $tableMaintainer,
9090
MetadataPool $metadataPool,
9191
\Magento\Framework\App\ResourceConnection $resource,
92+
BasePriceModifier $basePriceModifier,
9293
$fullReindexAction = false,
9394
$connectionName = 'indexer',
94-
$productType = \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE,
95-
array $priceModifiers = []
95+
$productType = \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE
9696
) {
9797
$this->baseFinalPrice = $baseFinalPrice;
9898
$this->indexTableStructureFactory = $indexTableStructureFactory;
9999
$this->tableMaintainer = $tableMaintainer;
100100
$this->productType = $productType;
101101
$this->connectionName = $connectionName;
102-
$this->priceModifiers = $priceModifiers;
103102
$this->metadataPool = $metadataPool;
104103
$this->resource = $resource;
105104
$this->fullReindexAction = $fullReindexAction;
105+
$this->basePriceModifier = $basePriceModifier;
106106
}
107107

108108
/**
@@ -130,23 +130,10 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
130130
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);
131131
$this->tableMaintainer->getConnection()->query($query);
132132

133-
$this->applyPriceModifiers($temporaryPriceTable);
133+
$this->basePriceModifier->modifyPrice($temporaryPriceTable, iterator_to_array($entityIds));
134134
$this->applyConfigurableOption($temporaryPriceTable, $dimensions, iterator_to_array($entityIds));
135135
}
136136

137-
/**
138-
* Apply price modifiers to temporary price index table
139-
*
140-
* @param IndexTableStructure $temporaryPriceTable
141-
* @return void
142-
*/
143-
private function applyPriceModifiers(IndexTableStructure $temporaryPriceTable)
144-
{
145-
foreach ($this->priceModifiers as $priceModifier) {
146-
$priceModifier->modifyPrice($temporaryPriceTable);
147-
}
148-
}
149-
150137
/**
151138
* @param IndexTableStructure $temporaryPriceTable
152139
* @param array $dimensions

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@
182182
<arguments>
183183
<argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
184184
<argument name="connectionName" xsi:type="string">indexer</argument>
185-
<argument name="priceModifiers" xsi:type="array">
186-
<item name="customOptionPriceModifier" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier</item>
187-
</argument>
188185
</arguments>
189186
</type>
190187
<type name="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Product">

app/code/Magento/Downloadable/Model/ResourceModel/Indexer/Price.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier;
1011
use Magento\Downloadable\Model\Product\Type;
1112
use Magento\Eav\Model\Config;
1213
use Magento\Framework\App\ResourceConnection;
@@ -16,7 +17,6 @@
1617
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPrice;
1718
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1819
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
19-
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
2020
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
2121
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
2222

@@ -66,15 +66,16 @@ class Price implements DimensionalIndexerInterface
6666
*/
6767
private $productType;
6868

69-
/**
70-
* @var PriceModifierInterface[]
71-
*/
72-
private $priceModifiers;
7369
/**
7470
* @var Config
7571
*/
7672
private $eavConfig;
7773

74+
/**
75+
* @var BasePriceModifier
76+
*/
77+
private $basePriceModifier;
78+
7879
/**
7980
* @param BaseFinalPrice $baseFinalPrice
8081
* @param IndexTableStructureFactory $indexTableStructureFactory
@@ -84,6 +85,7 @@ class Price implements DimensionalIndexerInterface
8485
* @param ResourceConnection $resource
8586
* @param string $connectionName
8687
* @param string $productType
88+
* @param BasePriceModifier $basePriceModifier
8789
* @param array $priceModifiers
8890
*/
8991
public function __construct(
@@ -93,19 +95,19 @@ public function __construct(
9395
MetadataPool $metadataPool,
9496
Config $eavConfig,
9597
ResourceConnection $resource,
98+
BasePriceModifier $basePriceModifier,
9699
$connectionName = 'indexer',
97-
$productType = Type::TYPE_DOWNLOADABLE,
98-
array $priceModifiers = []
100+
$productType = Type::TYPE_DOWNLOADABLE
99101
) {
100102
$this->baseFinalPrice = $baseFinalPrice;
101103
$this->indexTableStructureFactory = $indexTableStructureFactory;
102104
$this->tableMaintainer = $tableMaintainer;
103105
$this->productType = $productType;
104106
$this->connectionName = $connectionName;
105-
$this->priceModifiers = $priceModifiers;
106107
$this->metadataPool = $metadataPool;
107108
$this->resource = $resource;
108109
$this->eavConfig = $eavConfig;
110+
$this->basePriceModifier = $basePriceModifier;
109111
}
110112

111113
/**
@@ -128,23 +130,10 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
128130
'tierPriceField' => 'tier_price',
129131
]);
130132
$this->fillFinalPrice($dimensions, $entityIds, $temporaryPriceTable);
131-
$this->applyPriceModifiers($temporaryPriceTable);
133+
$this->basePriceModifier->modifyPrice($temporaryPriceTable, iterator_to_array($entityIds));
132134
$this->applyDownloadableLink($temporaryPriceTable, $dimensions);
133135
}
134136

135-
/**
136-
* Apply price modifiers to temporary price index table
137-
*
138-
* @param IndexTableStructure $temporaryPriceTable
139-
* @return void
140-
*/
141-
private function applyPriceModifiers(IndexTableStructure $temporaryPriceTable)
142-
{
143-
foreach ($this->priceModifiers as $priceModifier) {
144-
$priceModifier->modifyPrice($temporaryPriceTable);
145-
}
146-
}
147-
148137
/**
149138
* Calculate and apply Downloadable links price to index
150139
* @param IndexTableStructure $temporaryPriceTable
@@ -298,9 +287,11 @@ private function getTable($tableName)
298287
/**
299288
* @param array $dimensions
300289
* @param \Traversable $entityIds
301-
* @param $temporaryPriceTable
290+
* @param IndexTableStructure $temporaryPriceTable
291+
* @throws \Magento\Framework\Exception\LocalizedException
292+
* @throws \Zend_Db_Select_Exception
302293
*/
303-
private function fillFinalPrice(array $dimensions, \Traversable $entityIds, $temporaryPriceTable): void
294+
private function fillFinalPrice(array $dimensions, \Traversable $entityIds, IndexTableStructure $temporaryPriceTable)
304295
{
305296
$select = $this->baseFinalPrice->getQuery($dimensions, $this->productType, iterator_to_array($entityIds));
306297
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);

app/code/Magento/Downloadable/etc/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@
155155
<arguments>
156156
<argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
157157
<argument name="connectionName" xsi:type="string">indexer</argument>
158-
<argument name="priceModifiers" xsi:type="array">
159-
<item name="customOptionPriceModifier" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier</item>
160-
</argument>
161158
</arguments>
162159
</type>
163160
</config>

0 commit comments

Comments
 (0)