Skip to content

Commit

Permalink
Merge pull request #1409 from magento-plankton/2.2-bugs
Browse files Browse the repository at this point in the history
Bugs
- MAGETWO-71030 Sound from video from parent configurable product plays when start play video of child
- MAGETWO-71373 Cannot install EE without Staging modules
- MAGETWO-71242 Indexing fails on b2b medium profile
  • Loading branch information
VladimirZaets authored Aug 15, 2017
2 parents eed81bf + 1739b66 commit 18372e3
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 63 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
<argument name="estimators" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
</argument>
<argument name="batchSizeAdjusters" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster</item>
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Price">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;

/**
* Correct batch size according to number of composite related items.
*/
class CompositeProductBatchSizeAdjuster implements CompositeProductBatchSizeAdjusterInterface
{
/**
* @var CompositeProductRelationsCalculator
*/
private $compositeProductRelationsCalculator;

/**
* @param CompositeProductRelationsCalculator $compositeProductRelationsCalculator
*/
public function __construct(CompositeProductRelationsCalculator $compositeProductRelationsCalculator)
{
$this->compositeProductRelationsCalculator = $compositeProductRelationsCalculator;
}

/**
* {@inheritdoc}
*/
public function adjust($batchSize)
{
$maxRelationsCount = $this->compositeProductRelationsCalculator->getMaxRelationsCount();
return $maxRelationsCount > 0 ? ceil($batchSize / $maxRelationsCount) : $batchSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;

/**
* Correct batch size according to number of composite related items.
* @api
*/
interface CompositeProductBatchSizeAdjusterInterface
{
/**
* Correct batch size according to number of composite related items.
*
* @param int $batchSize
* @return int
*/
public function adjust($batchSize);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;

/**
* Class calculates composite product relations.
*/
class CompositeProductRelationsCalculator
{
/**
* @param DefaultPrice $indexerResource
*/
public function __construct(DefaultPrice $indexerResource)
{
$this->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInte
*/
const MEMORY_SIZE_FOR_ONE_ROW = 200;

/**
* @var DefaultPrice
*/
private $indexerResource;

/**
* @var WebsiteManagementInterface
*/
Expand All @@ -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;
}

/**
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
[]
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product\Indexer\Price;

use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductBatchSizeAdjuster;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductRelationsCalculator;

class CompositeProductBatchSizeAdjusterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CompositeProductBatchSizeAdjuster
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|CompositeProductRelationsCalculator
*/
private $relationsCalculatorMock;

protected function setUp()
{
$this->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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product\Indexer\Price;

use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductRelationsCalculator;

class CompositeProductRelationsCalculatorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|DefaultPrice
*/
private $defaultPriceMock;

/**
* @var CompositeProductRelationsCalculator
*/
private $model;

protected function setUp()
{
$this->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());
}
}
Loading

0 comments on commit 18372e3

Please sign in to comment.