Browse Source

making category progress clearer

imwald
Silberengel 5 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 @@ -111,6 +111,12 @@ final class PrewarmCommand extends Command
}
$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(
$io,
@ -128,17 +134,28 @@ final class PrewarmCommand extends Command @@ -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(
' <info>[%d/%d]</info> <comment>Fetched category index</comment><info>%s</info>',
$step,
$tot,
' <info>[category %d/%d]</info> <comment>Fetched category index</comment><info>%s</info>',
$ci,
$ct,
$tSlug
));
} 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 @@ -33,7 +33,7 @@ final class MagazineRefresher
*
* @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>),
* `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 @@ -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 @@ -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,
]);
}

Loading…
Cancel
Save