diff --git a/app/code/Magento/Bundle/etc/di.xml b/app/code/Magento/Bundle/etc/di.xml
index 9842b28efaa1c..287a6c8bfdbc0 100644
--- a/app/code/Magento/Bundle/etc/di.xml
+++ b/app/code/Magento/Bundle/etc/di.xml
@@ -160,6 +160,9 @@
- Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement
+
+ - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster
+
diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php
index 88dba03def001..eb15833a7d0b2 100644
--- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php
+++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php
@@ -106,6 +106,9 @@ public function execute($ids = null)
$this->_defaultIndexerResource->getMainTable()
);
+ // Prepare replica table for indexation.
+ $this->_defaultIndexerResource->getConnection()->truncateTable($replicaTable);
+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $indexer */
foreach ($this->getTypeIndexers() as $indexer) {
$indexer->getTableStrategy()->setUseIdxTable(false);
diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
index b31147af2342f..47c23b101a3b2 100644
--- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
+++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
@@ -21,15 +21,24 @@ class BatchSizeCalculator
*/
private $estimators;
+ /**
+ * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjusterInterface[]
+ * @since 2.2.0
+ */
+ private $batchSizeAdjusters;
+
/**
* BatchSizeCalculator constructor.
* @param array $batchRowsCount
* @param array $estimators
+ * @param array $batchSizeAdjusters
+ * @since 2.2.0
*/
- public function __construct(array $batchRowsCount, array $estimators)
+ public function __construct(array $batchRowsCount, array $estimators, array $batchSizeAdjusters)
{
$this->batchRowsCount = $batchRowsCount;
$this->estimators = $estimators;
+ $this->batchSizeAdjusters = $batchSizeAdjusters;
}
/**
@@ -52,6 +61,10 @@ public function estimateBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface
? $this->estimators[$indexerTypeId]
: $this->estimators['default'];
+ $batchRowsCount = isset($this->batchSizeAdjusters[$indexerTypeId])
+ ? $this->batchSizeAdjusters[$indexerTypeId]->adjust($batchRowsCount)
+ : $batchRowsCount;
+
$calculator->ensureBatchSize($connection, $batchRowsCount);
return $batchRowsCount;
diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjuster.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjuster.php
new file mode 100644
index 0000000000000..0054167c5386f
--- /dev/null
+++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjuster.php
@@ -0,0 +1,35 @@
+compositeProductRelationsCalculator = $compositeProductRelationsCalculator;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function adjust($batchSize)
+ {
+ $maxRelationsCount = $this->compositeProductRelationsCalculator->getMaxRelationsCount();
+ return $maxRelationsCount > 0 ? ceil($batchSize / $maxRelationsCount) : $batchSize;
+ }
+}
diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterInterface.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterInterface.php
new file mode 100644
index 0000000000000..5472527a85919
--- /dev/null
+++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterInterface.php
@@ -0,0 +1,22 @@
+indexerResource = $indexerResource;
+ }
+
+ /**
+ * Returns maximum number of composite related products.
+ *
+ * @return int
+ */
+ public function getMaxRelationsCount()
+ {
+ $connection = $this->indexerResource->getConnection();
+ $relationSelect = $connection->select();
+ $relationSelect->from(
+ ['relation' => $this->indexerResource->getTable('catalog_product_relation')],
+ ['count' => new \Zend_Db_Expr('count(relation.child_id)')]
+ );
+ $relationSelect->group('parent_id');
+
+ $maxSelect = $connection->select();
+ $maxSelect->from(
+ ['max_value' => $relationSelect],
+ ['count' => new \Zend_Db_Expr('MAX(count)')]
+ );
+ return $connection->fetchOne($maxSelect);
+ }
+}
diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php
index a3425bfc9d729..94a94c720b026 100644
--- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php
+++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php
@@ -20,11 +20,6 @@ class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInte
*/
const MEMORY_SIZE_FOR_ONE_ROW = 200;
- /**
- * @var DefaultPrice
- */
- private $indexerResource;
-
/**
* @var WebsiteManagementInterface
*/
@@ -36,18 +31,25 @@ class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInte
private $collectionFactory;
/**
- * @param DefaultPrice $indexerResource
+ * @var CompositeProductRelationsCalculator
+ * @since 2.2.0
+ */
+ private $compositeProductRelationsCalculator;
+
+ /**
* @param WebsiteManagementInterface $websiteManagement
* @param CollectionFactory $collectionFactory
+ * @param CompositeProductRelationsCalculator $compositeProductRelationsCalculator
+ * @since 2.2.0
*/
public function __construct(
- DefaultPrice $indexerResource,
WebsiteManagementInterface $websiteManagement,
- CollectionFactory $collectionFactory
+ CollectionFactory $collectionFactory,
+ CompositeProductRelationsCalculator $compositeProductRelationsCalculator
) {
- $this->indexerResource = $indexerResource;
$this->websiteManagement = $websiteManagement;
$this->collectionFactory = $collectionFactory;
+ $this->compositeProductRelationsCalculator = $compositeProductRelationsCalculator;
}
/**
@@ -59,21 +61,7 @@ public function estimateRowSize()
{
$websitesCount = $this->websiteManagement->getCount();
$customerGroupCount = $this->collectionFactory->create()->getSize();
-
- $connection = $this->indexerResource->getConnection();
- $relationSelect = $connection->select();
- $relationSelect->from(
- ['relation' => $this->indexerResource->getTable('catalog_product_relation')],
- ['count' => new \Zend_Db_Expr('count(relation.child_id)')]
- );
- $relationSelect->group('parent_id');
-
- $maxSelect = $connection->select();
- $maxSelect->from(
- ['max_value' => $relationSelect],
- ['count' => new \Zend_Db_Expr('MAX(count)')]
- );
- $maxRelatedProductCount = $connection->fetchOne($maxSelect);
+ $maxRelatedProductCount = $this->compositeProductRelationsCalculator->getMaxRelationsCount();
/**
* Calculate memory size for largest composite product in database.
diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculatorTest.php
index 74bce577f53a1..9508782cb4a99 100644
--- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculatorTest.php
+++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculatorTest.php
@@ -29,7 +29,8 @@ protected function setUp()
$this->batchRowsCount = 200;
$this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator(
['default' => $this->batchRowsCount],
- ['default' => $this->estimatorMock]
+ ['default' => $this->estimatorMock],
+ []
);
}
diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterTest.php
new file mode 100644
index 0000000000000..69def72af1669
--- /dev/null
+++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductBatchSizeAdjusterTest.php
@@ -0,0 +1,39 @@
+relationsCalculatorMock = $this->getMockBuilder(CompositeProductRelationsCalculator::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->model = new CompositeProductBatchSizeAdjuster($this->relationsCalculatorMock);
+ }
+
+ public function testAdjust()
+ {
+ $this->relationsCalculatorMock->expects($this->once())
+ ->method('getMaxRelationsCount')
+ ->willReturn(200);
+ $this->assertEquals(25, $this->model->adjust(5000));
+ }
+}
diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRelationsCalculatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRelationsCalculatorTest.php
new file mode 100644
index 0000000000000..3eda8616275a1
--- /dev/null
+++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRelationsCalculatorTest.php
@@ -0,0 +1,71 @@
+defaultPriceMock = $this->getMockBuilder(DefaultPrice::class)->disableOriginalConstructor()->getMock();
+ $this->model = new CompositeProductRelationsCalculator($this->defaultPriceMock);
+ }
+
+ public function testGetMaxRelationsCount()
+ {
+ $tableName = 'catalog_product_relation';
+ $maxRelatedProductCount = 200;
+
+ $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock();
+ $this->defaultPriceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
+ $this->defaultPriceMock->expects($this->once())->method('getTable')->with($tableName)->willReturn($tableName);
+
+ $relationSelectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $relationSelectMock->expects($this->once())
+ ->method('from')
+ ->with(
+ ['relation' => $tableName],
+ ['count' => 'count(relation.child_id)']
+ )
+ ->willReturnSelf();
+ $relationSelectMock->expects($this->once())->method('group')->with('parent_id')->willReturnSelf();
+ $connectionMock->expects($this->at(0))->method('select')->willReturn($relationSelectMock);
+
+ $maxSelectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $maxSelectMock->expects($this->once())
+ ->method('from')
+ ->with(
+ ['max_value' => $relationSelectMock],
+ ['count' => 'MAX(count)']
+ )
+ ->willReturnSelf();
+ $connectionMock->expects($this->at(1))->method('select')->willReturn($maxSelectMock);
+
+ $connectionMock->expects($this->at(2))
+ ->method('fetchOne')
+ ->with($maxSelectMock)
+ ->willReturn($maxRelatedProductCount);
+
+ $this->assertEquals($maxRelatedProductCount, $this->model->getMaxRelationsCount());
+ }
+}
diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimatorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimatorTest.php
index 2eefb4e715ad4..728044b89cafe 100644
--- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimatorTest.php
+++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimatorTest.php
@@ -23,7 +23,7 @@ class CompositeProductRowSizeEstimatorTest extends \PHPUnit\Framework\TestCase
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- private $defaultPriceMock;
+ private $relationsCalculatorMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -37,55 +37,27 @@ protected function setUp()
\Magento\Customer\Model\ResourceModel\Group\CollectionFactory::class,
['create']
);
- $this->defaultPriceMock = $this->createMock(
- \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice::class
+ $this->relationsCalculatorMock = $this->createMock(
+ \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductRelationsCalculator::class
);
$this->model = new CompositeProductRowSizeEstimator(
- $this->defaultPriceMock,
$this->websiteManagementMock,
- $this->collectionFactoryMock
+ $this->collectionFactoryMock,
+ $this->relationsCalculatorMock
);
}
public function testEstimateRowSize()
{
$expectedResult = 40000000;
- $tableName = 'catalog_product_relation';
$maxRelatedProductCount = 10;
$this->websiteManagementMock->expects($this->once())->method('getCount')->willReturn(100);
$collectionMock = $this->createMock(\Magento\Customer\Model\ResourceModel\Group\Collection::class);
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
$collectionMock->expects($this->once())->method('getSize')->willReturn(200);
-
- $connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
- $this->defaultPriceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
- $this->defaultPriceMock->expects($this->once())->method('getTable')->with($tableName)->willReturn($tableName);
-
- $relationSelectMock = $this->createMock(\Magento\Framework\DB\Select::class);
- $relationSelectMock->expects($this->once())
- ->method('from')
- ->with(
- ['relation' => $tableName],
- ['count' => 'count(relation.child_id)']
- )
- ->willReturnSelf();
- $relationSelectMock->expects($this->once())->method('group')->with('parent_id')->willReturnSelf();
- $connectionMock->expects($this->at(0))->method('select')->willReturn($relationSelectMock);
-
- $maxSelectMock = $this->createMock(\Magento\Framework\DB\Select::class);
- $maxSelectMock->expects($this->once())
- ->method('from')
- ->with(
- ['max_value' => $relationSelectMock],
- ['count' => 'MAX(count)']
- )
- ->willReturnSelf();
- $connectionMock->expects($this->at(1))->method('select')->willReturn($maxSelectMock);
-
- $connectionMock->expects($this->at(2))
- ->method('fetchOne')
- ->with($maxSelectMock)
+ $this->relationsCalculatorMock->expects($this->once())
+ ->method('getMaxRelationsCount')
->willReturn($maxRelatedProductCount);
$this->assertEquals(
diff --git a/app/code/Magento/ConfigurableProduct/etc/di.xml b/app/code/Magento/ConfigurableProduct/etc/di.xml
index 1ec382bf37b29..30fd8737c3820 100644
--- a/app/code/Magento/ConfigurableProduct/etc/di.xml
+++ b/app/code/Magento/ConfigurableProduct/etc/di.xml
@@ -180,6 +180,9 @@
- Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement
+
+ - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster
+
diff --git a/app/code/Magento/GroupedProduct/etc/di.xml b/app/code/Magento/GroupedProduct/etc/di.xml
index ff2cac0bd3186..f39bcfa01453c 100644
--- a/app/code/Magento/GroupedProduct/etc/di.xml
+++ b/app/code/Magento/GroupedProduct/etc/di.xml
@@ -94,6 +94,9 @@
- Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement
+
+ - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster
+
diff --git a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js
index f78e424d741eb..03ce42bf25c4a 100644
--- a/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js
+++ b/app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js
@@ -617,6 +617,7 @@ define([
var videoSettings;
videoSettings = this.options.videoSettings[0];
+ $image.find('.' + this.PV).remove();
$image.append(
'