Skip to content

Commit

Permalink
Merge pull request #1 from magento/2.4-develop
Browse files Browse the repository at this point in the history
abc
  • Loading branch information
gixid192 authored Jan 20, 2021
2 parents 1e846a4 + 3b860f5 commit 1be4239
Show file tree
Hide file tree
Showing 13 changed files with 707 additions and 107 deletions.
5 changes: 3 additions & 2 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ staleLabel: "stale issue"
# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed after 14 days if no further activity occurs. Thank you
for your contributions.
recent activity. It will be closed after 14 days if no further activity occurs.
Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
Thank you for your contributions!
# Comment to post when removing the stale label.
# unmarkComment: >
# Your comment here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Magento\Catalog\Model\Config;
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
use Magento\Catalog\Model\Indexer\Category\Product;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Query\Generator as QueryGenerator;
Expand Down Expand Up @@ -63,6 +65,18 @@ class Full extends AbstractAction
*/
private $processManager;

/**
* @var DeploymentConfig|null
*/
private $deploymentConfig;

/**
* Deployment config path
*
* @var string
*/
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';

/**
* @param ResourceConnection $resource
* @param StoreManagerInterface $storeManager
Expand All @@ -73,7 +87,8 @@ class Full extends AbstractAction
* @param MetadataPool|null $metadataPool
* @param int|null $batchRowsCount
* @param ActiveTableSwitcher|null $activeTableSwitcher
* @param ProcessManager $processManager
* @param ProcessManager|null $processManager
* @param DeploymentConfig|null $deploymentConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -86,7 +101,8 @@ public function __construct(
MetadataPool $metadataPool = null,
$batchRowsCount = null,
ActiveTableSwitcher $activeTableSwitcher = null,
ProcessManager $processManager = null
ProcessManager $processManager = null,
?DeploymentConfig $deploymentConfig = null
) {
parent::__construct(
$resource,
Expand All @@ -107,6 +123,7 @@ public function __construct(
$this->batchRowsCount = $batchRowsCount;
$this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class);
$this->processManager = $processManager ?: $objectManager->get(ProcessManager::class);
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
}

/**
Expand Down Expand Up @@ -266,6 +283,11 @@ private function reindexCategoriesBySelect(Select $basicSelect, $whereCondition,
$columns = array_keys(
$this->connection->describeTable($this->tableMaintainer->getMainTmpTable((int)$store->getId()))
);

$this->batchRowsCount = $this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . Product::INDEXER_ID
) ?? $this->batchRowsCount;

$this->batchSizeManagement->ensureBatchSize($this->connection, $this->batchRowsCount);

$select = $this->connection->select();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

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

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Model\Indexer\Product\Price\Processor;

/**
* Ensure that size of index MEMORY table is enough for configured rows count in batch.
*/
Expand All @@ -26,17 +30,34 @@ class BatchSizeCalculator
*/
private $batchSizeAdjusters;

/**
* @var DeploymentConfig|null
*/
private $deploymentConfig;

/**
* Deployment config path
*
* @var string
*/
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';

/**
* BatchSizeCalculator constructor.
* @param array $batchRowsCount
* @param array $estimators
* @param array $batchSizeAdjusters
*/
public function __construct(array $batchRowsCount, array $estimators, array $batchSizeAdjusters)
{
public function __construct(
array $batchRowsCount,
array $estimators,
array $batchSizeAdjusters,
?DeploymentConfig $deploymentConfig = null
) {
$this->batchRowsCount = $batchRowsCount;
$this->estimators = $estimators;
$this->batchSizeAdjusters = $batchSizeAdjusters;
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
}

/**
Expand All @@ -50,9 +71,18 @@ public function __construct(array $batchRowsCount, array $estimators, array $bat
*/
public function estimateBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $indexerTypeId)
{
$batchRowsCount = isset($this->batchRowsCount[$indexerTypeId])
? $this->batchRowsCount[$indexerTypeId]
: $this->batchRowsCount['default'];
$batchRowsCount = $this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . Processor::INDEXER_ID . '/' . $indexerTypeId,
$batchRowsCount = $this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . Processor::INDEXER_ID . '/' . 'default'
)
);

if (is_null($batchRowsCount)) {
$batchRowsCount = isset($this->batchRowsCount[$indexerTypeId])
? $this->batchRowsCount[$indexerTypeId]
: $this->batchRowsCount['default'];
}

/** @var \Magento\Framework\Indexer\BatchSizeManagementInterface $calculator */
$calculator = isset($this->estimators[$indexerTypeId])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Indexer\BatchSizeManagementInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Framework\App\DeploymentConfig;

class BatchSizeCalculatorTest extends TestCase
{
Expand All @@ -30,14 +31,20 @@ class BatchSizeCalculatorTest extends TestCase
*/
private $batchRowsCount;

/**
* @var DeploymentConfig|MockObject
*/
private $deploymentConfigMock;

protected function setUp(): void
{
$this->estimatorMock = $this->getMockForAbstractClass(BatchSizeManagementInterface::class);
$this->batchRowsCount = 200;
$this->model = new BatchSizeCalculator(
['default' => $this->batchRowsCount],
['default' => $this->estimatorMock],
[]
[],
$this->createMock(DeploymentConfig::class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction;
use Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\StockInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;

/**
* Class Full reindex action
Expand Down Expand Up @@ -71,6 +73,18 @@ class Full extends AbstractAction
*/
private $batchQueryGenerator;

/**
* @var DeploymentConfig|null
*/
private $deploymentConfig;

/**
* Deployment config path
*
* @var string
*/
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';

/**
* @param ResourceConnection $resource
* @param StockFactory $indexerFactory
Expand All @@ -83,6 +97,7 @@ class Full extends AbstractAction
* @param array $batchRowsCount
* @param ActiveTableSwitcher|null $activeTableSwitcher
* @param QueryGenerator|null $batchQueryGenerator
* @param DeploymentConfig|null $deploymentConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -96,7 +111,8 @@ public function __construct(
BatchProviderInterface $batchProvider = null,
array $batchRowsCount = [],
ActiveTableSwitcher $activeTableSwitcher = null,
QueryGenerator $batchQueryGenerator = null
QueryGenerator $batchQueryGenerator = null,
?DeploymentConfig $deploymentConfig = null
) {
parent::__construct(
$resource,
Expand All @@ -115,6 +131,7 @@ public function __construct(
$this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()
->get(ActiveTableSwitcher::class);
$this->batchQueryGenerator = $batchQueryGenerator ?: ObjectManager::getInstance()->get(QueryGenerator::class);
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
}

/**
Expand All @@ -141,9 +158,18 @@ public function execute($ids = null): void
$connection = $indexer->getConnection();
$tableName = $this->activeTableSwitcher->getAdditionalTableName($indexer->getMainTable());

$batchRowCount = isset($this->batchRowsCount[$indexer->getTypeId()])
? $this->batchRowsCount[$indexer->getTypeId()]
: $this->batchRowsCount['default'];
$batchRowCount = $this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . Processor::INDEXER_ID . '/' . $indexer->getTypeId(),
$this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . Processor::INDEXER_ID . '/' . 'default'
)
);

if (is_null($batchRowCount)) {
$batchRowCount = isset($this->batchRowsCount[$indexer->getTypeId()])
? $this->batchRowsCount[$indexer->getTypeId()]
: $this->batchRowsCount['default'];
}

$this->batchSizeManagement->ensureBatchSize($connection, $batchRowCount);

Expand Down
24 changes: 22 additions & 2 deletions app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
use Magento\Store\Model\StoreDimensionProvider;
use Magento\Indexer\Model\ProcessManager;
use Magento\Framework\App\DeploymentConfig;

/**
* Provide functionality for Fulltext Search indexing.
Expand Down Expand Up @@ -88,6 +89,18 @@ class Fulltext implements
*/
private $batchSize;

/**
* @var DeploymentConfig|null
*/
private $deploymentConfig;

/**
* Deployment config path
*
* @var string
*/
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';

/**
* @param FullFactory $fullActionFactory
* @param IndexerHandlerFactory $indexerHandlerFactory
Expand All @@ -96,8 +109,9 @@ class Fulltext implements
* @param StateFactory $indexScopeStateFactory
* @param DimensionProviderInterface $dimensionProvider
* @param array $data
* @param ProcessManager $processManager
* @param ProcessManager|null $processManager
* @param int|null $batchSize
* @param DeploymentConfig $deploymentConfig
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
Expand All @@ -109,7 +123,8 @@ public function __construct(
DimensionProviderInterface $dimensionProvider,
array $data,
ProcessManager $processManager = null,
?int $batchSize = null
?int $batchSize = null,
?DeploymentConfig $deploymentConfig = null
) {
$this->fullAction = $fullActionFactory->create(['data' => $data]);
$this->indexerHandlerFactory = $indexerHandlerFactory;
Expand All @@ -120,6 +135,7 @@ public function __construct(
$this->dimensionProvider = $dimensionProvider;
$this->processManager = $processManager ?: ObjectManager::getInstance()->get(ProcessManager::class);
$this->batchSize = $batchSize ?? self::BATCH_SIZE;
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
}

/**
Expand Down Expand Up @@ -165,6 +181,10 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
$currentBatch = [];
$i = 0;

$this->batchSize = $this->deploymentConfig->get(
self::DEPLOYMENT_CONFIG_INDEXER_BATCHES . self::INDEXER_ID
) ?? $this->batchSize;

foreach ($entityIds as $entityId) {
$currentBatch[] = $entityId;
if (++$i === $this->batchSize) {
Expand Down
Loading

0 comments on commit 1be4239

Please sign in to comment.