From c1317a6ff8ef6883ec451524b679b4540298aa38 Mon Sep 17 00:00:00 2001 From: Celestora Date: Wed, 6 Apr 2022 11:22:43 +0300 Subject: [PATCH] Enrich progress reporting for build-images command --- CLI/RebuildImagesCommand.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/CLI/RebuildImagesCommand.php b/CLI/RebuildImagesCommand.php index cd34ee2e..cc5a4be5 100644 --- a/CLI/RebuildImagesCommand.php +++ b/CLI/RebuildImagesCommand.php @@ -1,7 +1,7 @@ getOption("upgrade-only")) $filter["sizes"] = NULL; - $selection = $this->images->where($filter); + $selection = $this->images->select("id")->where($filter); + $totalPics = $selection->count(); $header->writeln([ - "Total of " . $selection->count() . " images found.", + "Total of $totalPics images found.", "", ]); - $i = 0; - foreach($selection as $img) { - $photo = new Photo($img); + $count = 0; + $avgTime = NULL; + $begin = new \DateTimeImmutable("now"); + foreach($selection as $idHolder) { + $start = microtime(true); + $photo = (new Photos)->get($idHolder->id); $photo->getSizes(true, true); $photo->getDimensions(); - $counter->overwrite("Processed " . ++$i . " images..."); + $timeConsumed = microtime(true) - $start; + if(!$avgTime) + $avgTime = $timeConsumed; + else + $avgTime = ($avgTime + $timeConsumed) / 2; + + $eta = $begin->getTimestamp() + ceil($totalPics * $avgTime); + $int = (new \DateTimeImmutable("now"))->diff(new \DateTimeImmutable("@$eta")); + $int = $int->d . "d" . $int->h . "h" . $int->i . "m" . $int->s . "s"; + $pct = floor(100 * ($count / $totalPics)); + + $counter->overwrite("Processed " . ++$count . " images... ($pct% $int left)"); } $counter->overwrite("Processing finished :3");