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");