Skip to content

Commit 6dbb7fc

Browse files
authored
Merge pull request #7981 from magento-performance/ACPT-860
[Performance] ACPT-860: Indexation time is calculated incorrectly
2 parents f00af58 + 1b1efa3 commit 6dbb7fc

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
101101

102102
$output->write($indexer->getTitle() . ' index ');
103103

104-
$startTime = microtime(true);
104+
$startTime = new \DateTimeImmutable();
105105
$indexerConfig = $this->getConfig()->getIndexer($indexer->getId());
106106
$sharedIndex = $indexerConfig['shared_index'] ?? null;
107107

@@ -112,10 +112,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
112112
$this->sharedIndexesComplete[] = $sharedIndex;
113113
}
114114
}
115-
$resultTime = microtime(true) - $startTime;
115+
$endTime = new \DateTimeImmutable();
116+
$interval = $startTime->diff($endTime);
117+
$days = $interval->format('%d');
118+
$hours = $days > 0 ? $days * 24 + $interval->format('%H') : $interval->format('%H');
119+
$minutes = $interval->format('%I');
120+
$seconds = $interval->format('%S');
116121

117122
$output->writeln(
118-
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', (int) $resultTime)])
123+
__('has been rebuilt successfully in %1:%2:%3', $hours, $minutes, $seconds)
119124
);
120125
} catch (\Throwable $e) {
121126
$output->writeln('process error during indexation process:');
@@ -238,7 +243,9 @@ private function validateIndexerStatus(IndexerInterface $indexer)
238243
* Get config
239244
*
240245
* @return ConfigInterface
241-
* @deprecated 100.1.0
246+
* @deprecated 100.1.0 We don't recommend this approach anymore
247+
* @see Add a new optional parameter to the constructor at the end of the arguments list instead
248+
* and fetch the dependency using Magento\Framework\App\ObjectManager::getInstance() in the constructor body
242249
*/
243250
private function getConfig()
244251
{
@@ -252,7 +259,9 @@ private function getConfig()
252259
* Get dependency info provider
253260
*
254261
* @return DependencyInfoProvider
255-
* @deprecated 100.2.0
262+
* @deprecated 100.2.0 We don't recommend this approach anymore
263+
* @see Add a new optional parameter to the constructor at the end of the arguments list instead
264+
* and fetch the dependency using Magento\Framework\App\ObjectManager::getInstance() in the constructor body
256265
*/
257266
private function getDependencyInfoProvider()
258267
{

app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
namespace Magento\Indexer\Test\Unit\Console\Command;
99

1010
use Magento\Framework\Console\Cli;
11-
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\Indexer\Config\DependencyInfoProvider;
1312
use Magento\Framework\Indexer\ConfigInterface;
1413
use Magento\Framework\Indexer\IndexerInterface;
1514
use Magento\Framework\Indexer\IndexerRegistry;
1615
use Magento\Framework\Indexer\StateInterface;
17-
use Magento\Framework\Phrase;
1816
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1917
use Magento\Indexer\Console\Command\IndexerReindexCommand;
2018
use Magento\Indexer\Model\Config;
@@ -27,7 +25,7 @@
2725
*/
2826
class IndexerReindexCommandTest extends AbstractIndexerCommandCommonSetup
2927
{
30-
const STUB_INDEXER_NAME = 'Indexer Name';
28+
private const STUB_INDEXER_NAME = 'Indexer Name';
3129
/**
3230
* Command being tested
3331
*
@@ -130,6 +128,11 @@ public function testExecuteAll()
130128
self::STUB_INDEXER_NAME . ' index has been rebuilt successfully in',
131129
$actualValue
132130
);
131+
$this->assertMatchesRegularExpression(
132+
'/' . self::STUB_INDEXER_NAME
133+
. ' index has been rebuilt successfully in (?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)/m',
134+
$actualValue
135+
);
133136
}
134137

135138
/**

0 commit comments

Comments
 (0)