-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into pr-sprint-15
- Loading branch information
Showing
20 changed files
with
1,018 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/BatchSizeCalculator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav; | ||
|
||
use Magento\Framework\DB\Adapter\AdapterInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
/** | ||
* Composite batch size calculator for EAV related indexers. | ||
* | ||
* Can be configured to provide batch sizes for different indexer types. | ||
*/ | ||
class BatchSizeCalculator | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $batchSizes; | ||
|
||
/** | ||
* @var \Magento\Framework\Indexer\BatchSizeManagement[] | ||
*/ | ||
private $batchSizeManagers; | ||
|
||
/** | ||
* @param array $batchSizes preferable sizes (number of rows in batch) of batches per index type | ||
* @param array $batchSizeManagers batch managers per index type | ||
*/ | ||
public function __construct( | ||
array $batchSizes, | ||
array $batchSizeManagers | ||
) { | ||
$this->batchSizes = $batchSizes; | ||
$this->batchSizeManagers = $batchSizeManagers; | ||
} | ||
|
||
/** | ||
* Estimate batch size and ensure that database will be able to handle it properly. | ||
* | ||
* @param AdapterInterface $connection | ||
* @param string $indexerTypeId unique identifier of the indexer | ||
* @return int estimated batch size | ||
* @throws NoSuchEntityException thrown if indexer identifier is not recognized | ||
*/ | ||
public function estimateBatchSize( | ||
AdapterInterface $connection, | ||
$indexerTypeId | ||
) { | ||
if (!isset($this->batchSizes[$indexerTypeId])) { | ||
throw NoSuchEntityException::singleField('indexTypeId', $indexerTypeId); | ||
} | ||
$this->batchSizeManagers[$indexerTypeId]->ensureBatchSize($connection, $this->batchSizes[$indexerTypeId]); | ||
|
||
return $this->batchSizes[$indexerTypeId]; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/DecimalRowSizeEstimator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav; | ||
|
||
use Magento\Store\Api\StoreManagementInterface; | ||
use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
/** | ||
* Estimator of the EAV decimal index table row size. | ||
* | ||
* Estimates the amount of memory required to store the index data of the product | ||
* with the highest number of attributes/values. | ||
* | ||
* Can be used with batch size manager to ensure that the batch will be handled correctly by the database. | ||
* @see \Magento\Framework\Indexer\BatchSizeManagement | ||
*/ | ||
class DecimalRowSizeEstimator implements IndexTableRowSizeEstimatorInterface | ||
{ | ||
/** | ||
* @var Decimal | ||
*/ | ||
private $indexerResource; | ||
|
||
/** | ||
* @var StoreManagementInterface | ||
*/ | ||
private $storeManagement; | ||
|
||
/** | ||
* @var MetadataPool | ||
*/ | ||
private $metadataPool; | ||
|
||
/** | ||
* @param StoreManagementInterface $storeManagement | ||
* @param Decimal $indexerResource | ||
* @param MetadataPool $metadataPool | ||
*/ | ||
public function __construct( | ||
StoreManagementInterface $storeManagement, | ||
Decimal $indexerResource, | ||
MetadataPool $metadataPool | ||
) { | ||
$this->storeManagement = $storeManagement; | ||
$this->indexerResource = $indexerResource; | ||
$this->metadataPool = $metadataPool; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function estimateRowSize() | ||
{ | ||
$connection = $this->indexerResource->getConnection(); | ||
$entityIdField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); | ||
|
||
$valueSelect = $connection->select(); | ||
$valueSelect->from( | ||
['value_table' => $this->indexerResource->getTable('catalog_product_entity_decimal')], | ||
['count' => new \Zend_Db_Expr('count(value_table.value_id)')] | ||
); | ||
$valueSelect->group([$entityIdField, 'store_id']); | ||
|
||
$maxSelect = $connection->select(); | ||
$maxSelect->from( | ||
['max_value' => $valueSelect], | ||
['count' => new \Zend_Db_Expr('MAX(count)')] | ||
); | ||
$maxRowsPerStore = $connection->fetchOne($maxSelect); | ||
|
||
return ceil($maxRowsPerStore * $this->storeManagement->getCount() * 500); | ||
} | ||
} |
Oops, something went wrong.