Browse Source

making category progress clearer

imwald
Silberengel 7 days ago
parent
commit
16df037f2f
  1. 31
      src/Command/PrewarmCommand.php
  2. 7
      src/Service/MagazineRefresher.php

31
src/Command/PrewarmCommand.php

@ -111,6 +111,12 @@ final class PrewarmCommand extends Command
} }
$io->writeln(sprintf(' · <info>%s</info>', $s)); $io->writeln(sprintf(' · <info>%s</info>', $s));
} }
$io->writeln(sprintf(
' <comment>Progress bar: <info>%d</info> steps = <info>1</info> (root) + <info>%d</info> (categor%s).</comment>',
1 + $n,
$n,
$n === 1 ? 'y' : 'ies'
));
} }
$bar = $this->createPrewarmProgressBar( $bar = $this->createPrewarmProgressBar(
$io, $io,
@ -128,17 +134,28 @@ final class PrewarmCommand extends Command
} }
$bar->setMessage($tSlug !== '' ? 'Category: '.$tSlug : 'Category'); $bar->setMessage($tSlug !== '' ? 'Category: '.$tSlug : 'Category');
if ($tSlug !== '') { if ($tSlug !== '') {
$step = (int) ($p['step'] ?? 0); $ci = (int) ($p['category_index'] ?? 0);
$tot = (int) ($p['total_steps'] ?? 0); $ct = (int) ($p['category_total'] ?? 0);
if ($tot > 0) { if ($ci > 0 && $ct > 0) {
$io->writeln(sprintf( $io->writeln(sprintf(
' <info>[%d/%d]</info> <comment>Fetched category index</comment><info>%s</info>', ' <info>[category %d/%d]</info> <comment>Fetched category index</comment><info>%s</info>',
$step, $ci,
$tot, $ct,
$tSlug $tSlug
)); ));
} else { } else {
$io->writeln(sprintf(' <comment>Fetched category index</comment><info>%s</info>', $tSlug)); $st = (int) ($p['step'] ?? 0);
$tot = (int) ($p['total_steps'] ?? 0);
if ($tot > 0) {
$io->writeln(sprintf(
' <info>[%d/%d]</info> <comment>Fetched category index</comment><info>%s</info>',
$st,
$tot,
$tSlug
));
} else {
$io->writeln(sprintf(' <comment>Fetched category index</comment><info>%s</info>', $tSlug));
}
} }
} }
} }

7
src/Service/MagazineRefresher.php

@ -33,7 +33,7 @@ final class MagazineRefresher
* *
* @param (callable(string, array<string, int|string|bool|null>): void)|null $onProgress * @param (callable(string, array<string, int|string|bool|null>): void)|null $onProgress
* Phases: `before_root`, `after_root` (total_steps, step, slug_count, slugs: list<string>), * Phases: `before_root`, `after_root` (total_steps, step, slug_count, slugs: list<string>),
* `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 public function refreshFromRelays(int $budgetSeconds = 8, array $preferSlugs = [], ?callable $onProgress = null): void
{ {
@ -76,6 +76,8 @@ final class MagazineRefresher
'slugs' => $slugs, 'slugs' => $slugs,
]); ]);
$step = 1; $step = 1;
$catTotal = \count($slugs);
$catIndex = 0;
foreach ($slugs as $slug) { foreach ($slugs as $slug) {
if (microtime(true) >= $deadline) { if (microtime(true) >= $deadline) {
$this->logger->notice('MagazineRefresher: stopped at time budget; some categories not fetched', [ $this->logger->notice('MagazineRefresher: stopped at time budget; some categories not fetched', [
@ -100,9 +102,12 @@ final class MagazineRefresher
]); ]);
} finally { } finally {
++$step; ++$step;
++$catIndex;
$onProgress?->__invoke('category_fetched', [ $onProgress?->__invoke('category_fetched', [
'step' => $step, 'step' => $step,
'total_steps' => $totalSteps, 'total_steps' => $totalSteps,
'category_index' => $catIndex,
'category_total' => $catTotal,
'slug' => $slug, 'slug' => $slug,
]); ]);
} }

Loading…
Cancel
Save