diff --git a/src/Command/PrewarmCommand.php b/src/Command/PrewarmCommand.php index 936f891..cdbc183 100644 --- a/src/Command/PrewarmCommand.php +++ b/src/Command/PrewarmCommand.php @@ -111,6 +111,12 @@ final class PrewarmCommand extends Command } $io->writeln(sprintf(' · %s', $s)); } + $io->writeln(sprintf( + ' Progress bar: %d steps = 1 (root) + %d (categor%s).', + 1 + $n, + $n, + $n === 1 ? 'y' : 'ies' + )); } $bar = $this->createPrewarmProgressBar( $io, @@ -128,17 +134,28 @@ final class PrewarmCommand extends Command } $bar->setMessage($tSlug !== '' ? 'Category: '.$tSlug : 'Category'); if ($tSlug !== '') { - $step = (int) ($p['step'] ?? 0); - $tot = (int) ($p['total_steps'] ?? 0); - if ($tot > 0) { + $ci = (int) ($p['category_index'] ?? 0); + $ct = (int) ($p['category_total'] ?? 0); + if ($ci > 0 && $ct > 0) { $io->writeln(sprintf( - ' [%d/%d] Fetched category index%s', - $step, - $tot, + ' [category %d/%d] Fetched category index%s', + $ci, + $ct, $tSlug )); } else { - $io->writeln(sprintf(' Fetched category index%s', $tSlug)); + $st = (int) ($p['step'] ?? 0); + $tot = (int) ($p['total_steps'] ?? 0); + if ($tot > 0) { + $io->writeln(sprintf( + ' [%d/%d] Fetched category index%s', + $st, + $tot, + $tSlug + )); + } else { + $io->writeln(sprintf(' Fetched category index%s', $tSlug)); + } } } } diff --git a/src/Service/MagazineRefresher.php b/src/Service/MagazineRefresher.php index 8ba3cd3..1cfdfd0 100644 --- a/src/Service/MagazineRefresher.php +++ b/src/Service/MagazineRefresher.php @@ -33,7 +33,7 @@ final class MagazineRefresher * * @param (callable(string, array): void)|null $onProgress * Phases: `before_root`, `after_root` (total_steps, step, slug_count, slugs: list), - * `category_fetched` (step, total_steps, slug) + * `category_fetched` (step, total_steps, category_index, category_total, slug) */ public function refreshFromRelays(int $budgetSeconds = 8, array $preferSlugs = [], ?callable $onProgress = null): void { @@ -76,6 +76,8 @@ final class MagazineRefresher 'slugs' => $slugs, ]); $step = 1; + $catTotal = \count($slugs); + $catIndex = 0; foreach ($slugs as $slug) { if (microtime(true) >= $deadline) { $this->logger->notice('MagazineRefresher: stopped at time budget; some categories not fetched', [ @@ -100,9 +102,12 @@ final class MagazineRefresher ]); } finally { ++$step; + ++$catIndex; $onProgress?->__invoke('category_fetched', [ 'step' => $step, 'total_steps' => $totalSteps, + 'category_index' => $catIndex, + 'category_total' => $catTotal, 'slug' => $slug, ]); }