Skip to content

Commit 85d7673

Browse files
author
Magento CICD
authored
merge magento/2.2-develop into magento-frontend/PR_09_08
2 parents 9f0a1fa + a4c37be commit 85d7673

File tree

31 files changed

+680
-525
lines changed

31 files changed

+680
-525
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
<argument name="estimators" xsi:type="array">
161161
<item name="bundle" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
162162
</argument>
163+
<argument name="batchSizeAdjusters" xsi:type="array">
164+
<item name="bundle" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster</item>
165+
</argument>
163166
</arguments>
164167
</type>
165168
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Price">

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public function execute($ids = null)
106106
$this->_defaultIndexerResource->getMainTable()
107107
);
108108

109+
// Prepare replica table for indexation.
110+
$this->_defaultIndexerResource->getConnection()->truncateTable($replicaTable);
111+
109112
/** @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $indexer */
110113
foreach ($this->getTypeIndexers() as $indexer) {
111114
$indexer->getTableStrategy()->setUseIdxTable(false);

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
641641
}
642642
unset($this->instances[$product->getSku()]);
643643
unset($this->instancesById[$product->getId()]);
644-
return $this->get($product->getSku());
644+
return $this->get($product->getSku(), false, $product->getStoreId());
645645
}
646646

647647
/**

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ class BatchSizeCalculator
2121
*/
2222
private $estimators;
2323

24+
/**
25+
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjusterInterface[]
26+
* @since 2.2.0
27+
*/
28+
private $batchSizeAdjusters;
29+
2430
/**
2531
* BatchSizeCalculator constructor.
2632
* @param array $batchRowsCount
2733
* @param array $estimators
34+
* @param array $batchSizeAdjusters
35+
* @since 2.2.0
2836
*/
29-
public function __construct(array $batchRowsCount, array $estimators)
37+
public function __construct(array $batchRowsCount, array $estimators, array $batchSizeAdjusters)
3038
{
3139
$this->batchRowsCount = $batchRowsCount;
3240
$this->estimators = $estimators;
41+
$this->batchSizeAdjusters = $batchSizeAdjusters;
3342
}
3443

3544
/**
@@ -52,6 +61,10 @@ public function estimateBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface
5261
? $this->estimators[$indexerTypeId]
5362
: $this->estimators['default'];
5463

64+
$batchRowsCount = isset($this->batchSizeAdjusters[$indexerTypeId])
65+
? $this->batchSizeAdjusters[$indexerTypeId]->adjust($batchRowsCount)
66+
: $batchRowsCount;
67+
5568
$calculator->ensureBatchSize($connection, $batchRowsCount);
5669

5770
return $batchRowsCount;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
8+
9+
/**
10+
* Correct batch size according to number of composite related items.
11+
*/
12+
class CompositeProductBatchSizeAdjuster implements CompositeProductBatchSizeAdjusterInterface
13+
{
14+
/**
15+
* @var CompositeProductRelationsCalculator
16+
*/
17+
private $compositeProductRelationsCalculator;
18+
19+
/**
20+
* @param CompositeProductRelationsCalculator $compositeProductRelationsCalculator
21+
*/
22+
public function __construct(CompositeProductRelationsCalculator $compositeProductRelationsCalculator)
23+
{
24+
$this->compositeProductRelationsCalculator = $compositeProductRelationsCalculator;
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function adjust($batchSize)
31+
{
32+
$maxRelationsCount = $this->compositeProductRelationsCalculator->getMaxRelationsCount();
33+
return $maxRelationsCount > 0 ? ceil($batchSize / $maxRelationsCount) : $batchSize;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
8+
9+
/**
10+
* Correct batch size according to number of composite related items.
11+
* @api
12+
*/
13+
interface CompositeProductBatchSizeAdjusterInterface
14+
{
15+
/**
16+
* Correct batch size according to number of composite related items.
17+
*
18+
* @param int $batchSize
19+
* @return int
20+
*/
21+
public function adjust($batchSize);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
8+
9+
/**
10+
* Class calculates composite product relations.
11+
*/
12+
class CompositeProductRelationsCalculator
13+
{
14+
/**
15+
* @param DefaultPrice $indexerResource
16+
*/
17+
public function __construct(DefaultPrice $indexerResource)
18+
{
19+
$this->indexerResource = $indexerResource;
20+
}
21+
22+
/**
23+
* Returns maximum number of composite related products.
24+
*
25+
* @return int
26+
*/
27+
public function getMaxRelationsCount()
28+
{
29+
$connection = $this->indexerResource->getConnection();
30+
$relationSelect = $connection->select();
31+
$relationSelect->from(
32+
['relation' => $this->indexerResource->getTable('catalog_product_relation')],
33+
['count' => new \Zend_Db_Expr('count(relation.child_id)')]
34+
);
35+
$relationSelect->group('parent_id');
36+
37+
$maxSelect = $connection->select();
38+
$maxSelect->from(
39+
['max_value' => $relationSelect],
40+
['count' => new \Zend_Db_Expr('MAX(count)')]
41+
);
42+
return $connection->fetchOne($maxSelect);
43+
}
44+
}

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInte
2020
*/
2121
const MEMORY_SIZE_FOR_ONE_ROW = 200;
2222

23-
/**
24-
* @var DefaultPrice
25-
*/
26-
private $indexerResource;
27-
2823
/**
2924
* @var WebsiteManagementInterface
3025
*/
@@ -36,18 +31,25 @@ class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInte
3631
private $collectionFactory;
3732

3833
/**
39-
* @param DefaultPrice $indexerResource
34+
* @var CompositeProductRelationsCalculator
35+
* @since 2.2.0
36+
*/
37+
private $compositeProductRelationsCalculator;
38+
39+
/**
4040
* @param WebsiteManagementInterface $websiteManagement
4141
* @param CollectionFactory $collectionFactory
42+
* @param CompositeProductRelationsCalculator $compositeProductRelationsCalculator
43+
* @since 2.2.0
4244
*/
4345
public function __construct(
44-
DefaultPrice $indexerResource,
4546
WebsiteManagementInterface $websiteManagement,
46-
CollectionFactory $collectionFactory
47+
CollectionFactory $collectionFactory,
48+
CompositeProductRelationsCalculator $compositeProductRelationsCalculator
4749
) {
48-
$this->indexerResource = $indexerResource;
4950
$this->websiteManagement = $websiteManagement;
5051
$this->collectionFactory = $collectionFactory;
52+
$this->compositeProductRelationsCalculator = $compositeProductRelationsCalculator;
5153
}
5254

5355
/**
@@ -59,21 +61,7 @@ public function estimateRowSize()
5961
{
6062
$websitesCount = $this->websiteManagement->getCount();
6163
$customerGroupCount = $this->collectionFactory->create()->getSize();
62-
63-
$connection = $this->indexerResource->getConnection();
64-
$relationSelect = $connection->select();
65-
$relationSelect->from(
66-
['relation' => $this->indexerResource->getTable('catalog_product_relation')],
67-
['count' => new \Zend_Db_Expr('count(relation.child_id)')]
68-
);
69-
$relationSelect->group('parent_id');
70-
71-
$maxSelect = $connection->select();
72-
$maxSelect->from(
73-
['max_value' => $relationSelect],
74-
['count' => new \Zend_Db_Expr('MAX(count)')]
75-
);
76-
$maxRelatedProductCount = $connection->fetchOne($maxSelect);
64+
$maxRelatedProductCount = $this->compositeProductRelationsCalculator->getMaxRelationsCount();
7765

7866
/**
7967
* Calculate memory size for largest composite product in database.

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ protected function setUp()
193193
'validate',
194194
'save',
195195
'getMediaGalleryEntries',
196-
'setData'
196+
'setData',
197+
'getStoreId'
197198
]);
198199
$this->initializedProductMock->expects($this->any())
199200
->method('hasGalleryAttribute')

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected function setUp()
2929
$this->batchRowsCount = 200;
3030
$this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator(
3131
['default' => $this->batchRowsCount],
32-
['default' => $this->estimatorMock]
32+
['default' => $this->estimatorMock],
33+
[]
3334
);
3435
}
3536

0 commit comments

Comments
 (0)