Skip to content

Commit

Permalink
ResultCacheManager: output restore time in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Jul 11, 2024
1 parent 18706de commit 998f817
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
use function is_array;
use function is_file;
use function ksort;
use function microtime;
use function round;
use function sha1_file;
use function sort;
use function sprintf;
Expand Down Expand Up @@ -88,6 +90,7 @@ public function __construct(
*/
public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?array $projectConfigArray, Output $output): ResultCache
{
$startTime = microtime(true);
if ($debug) {
if ($output->isDebug()) {
$output->writeLineFormatted('Result cache not used because of debug mode.');
Expand Down Expand Up @@ -285,8 +288,14 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
$filesToAnalyseCount = count($filesToAnalyse);

if ($output->isDebug()) {
$elapsed = microtime(true) - $startTime;
$elapsedString = $elapsed > 5
? sprintf(' in %f seconds', round($elapsed, 1))
: '';

$output->writeLineFormatted(sprintf(
'Result cache restored. %d %s will be reanalysed.',
'Result cache restored%s. %d %s will be reanalysed.',
$elapsedString,
$filesToAnalyseCount,
$filesToAnalyseCount === 1 ? 'file' : 'files',
));
Expand Down

0 comments on commit 998f817

Please sign in to comment.