From 63ea968ee4dd8c56d70238ad3b220c98f0d0556d Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 13 Sep 2018 09:56:47 +0200 Subject: [PATCH] Use now() helper and related functions for time calculations in ProcessReleases class --- Blacklight/processing/ProcessReleases.php | 58 ++++++++++++----------- Changelog | 1 + 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Blacklight/processing/ProcessReleases.php b/Blacklight/processing/ProcessReleases.php index bf1ee447e4..2ebbbc9883 100755 --- a/Blacklight/processing/ProcessReleases.php +++ b/Blacklight/processing/ProcessReleases.php @@ -281,11 +281,13 @@ public function categorizeRelease($type, $where = ''): int /** * @param $groupID + * * @throws \Exception + * @throws \Throwable */ public function processIncompleteCollections($groupID): void { - $startTime = time(); + $startTime = now(); $this->initiateTableNames($groupID); if ($this->echoCLI) { @@ -317,7 +319,7 @@ public function processIncompleteCollections($groupID): void ColorCLI::doEcho( ColorCLI::primary( ($count === null ? 0 : $count->complete).' collections were found to be complete. Time: '. - $this->consoleTools->convertTime(time() - $startTime) + now()->diffInSeconds($startTime).' seconds' ), true ); @@ -331,7 +333,7 @@ public function processIncompleteCollections($groupID): void */ public function processCollectionSizes($groupID): void { - $startTime = time(); + $startTime = now(); $this->initiateTableNames($groupID); if ($this->echoCLI) { @@ -365,7 +367,7 @@ public function processCollectionSizes($groupID): void ), true ); - ColorCLI::doEcho(ColorCLI::primary($this->consoleTools->convertTime(time() - $startTime)), true); + ColorCLI::doEcho(ColorCLI::primary(now()->diffInSeconds($startTime).' seconds'), true); } } @@ -377,7 +379,7 @@ public function processCollectionSizes($groupID): void */ public function deleteUnwantedCollections($groupID): void { - $startTime = time(); + $startTime = now(); $this->initiateTableNames($groupID); if ($this->echoCLI) { @@ -498,7 +500,7 @@ public function deleteUnwantedCollections($groupID): void $minSizeDeleted.' smaller than, '. $maxSizeDeleted.' bigger than, '. $minFilesDeleted.' with less files than site/group settings in: '. - $this->consoleTools->convertTime(time() - $startTime) + now()->diffInSeconds($startTime).' seconds' ), true ); @@ -533,7 +535,7 @@ protected function formFromNamesQuery(): void */ public function createReleases($groupID): array { - $startTime = time(); + $startTime = now(); $this->initiateTableNames($groupID); $categorize = new Categorize(); @@ -716,7 +718,7 @@ public function createReleases($groupID): array ' Releases added and '. number_format($duplicate). ' duplicate collections deleted in '. - $this->consoleTools->convertTime(time() - $startTime) + now()->diffInSeconds($startTime).' seconds' ), true ); @@ -735,7 +737,7 @@ public function createReleases($groupID): array */ public function createNZBs($groupID): int { - $startTime = time(); + $startTime = now(); $this->formFromNamesQuery(); if ($this->echoCLI) { @@ -773,14 +775,14 @@ public function createNZBs($groupID): int } } - $totalTime = (time() - $startTime); + $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { ColorCLI::doEcho( ColorCLI::primary( number_format($nzbCount).' NZBs created/Collections deleted in '. $totalTime.' seconds.'.PHP_EOL. - 'Total time: '.ColorCLI::primary($this->consoleTools->convertTime($totalTime)).PHP_EOL + 'Total time: '.ColorCLI::primary($totalTime).' seconds' ), true ); @@ -800,7 +802,7 @@ public function createNZBs($groupID): int */ public function categorizeReleases($categorize, $groupID = ''): void { - $startTime = time(); + $startTime = now(); if ($this->echoCLI) { echo ColorCLI::header('Process Releases -> Categorize releases.'); } @@ -822,7 +824,7 @@ public function categorizeReleases($categorize, $groupID = ''): void ); if ($this->echoCLI) { - ColorCLI::doEcho(ColorCLI::primary($this->consoleTools->convertTime(time() - $startTime)), true); + ColorCLI::doEcho(ColorCLI::primary(now()->diffInSeconds($startTime).' seconds'), true); } } @@ -858,7 +860,7 @@ public function postProcessReleases($postProcess, &$nntp): void */ public function deleteCollections($groupID): void { - $startTime = time(); + $startTime = now(); $this->initiateTableNames($groupID); $deletedCount = 0; @@ -892,12 +894,12 @@ public function deleteCollections($groupID): void $deletedCount += $deleted; } - $firstQuery = $fourthQuery = time(); + $firstQuery = $fourthQuery = now(); if ($this->echoCLI) { echo ColorCLI::primary( 'Finished deleting '.$deleted.' old collections/binaries/parts in '. - ($firstQuery - $startTime).' seconds.'.PHP_EOL + $firstQuery->diffInSeconds($startTime).' seconds.'.PHP_EOL ); } @@ -933,12 +935,12 @@ public function deleteCollections($groupID): void $deletedCount += $deleted; } - $secondQuery = time(); + $secondQuery = now(); if ($this->echoCLI) { echo ColorCLI::primary( 'Finished deleting '.$deleted.' orphaned collections in '. - ($secondQuery - $firstQuery).' seconds.'.PHP_EOL + $secondQuery->diffInSeconds($firstQuery).' seconds.'.PHP_EOL ); } @@ -970,12 +972,12 @@ public function deleteCollections($groupID): void $deletedCount += $deleted; } - $thirdQuery = time(); + $thirdQuery = now(); if ($this->echoCLI) { echo ColorCLI::primary( 'Finished deleting '.$deleted.' binaries with no collections or parts in '. - ($thirdQuery - $secondQuery).' seconds.' + $thirdQuery->diffInSeconds($secondQuery).' seconds.' ); } @@ -1006,12 +1008,12 @@ public function deleteCollections($groupID): void $deletedCount += $deleted; } - $fourthQuery = time(); + $fourthQuery = now(); if ($this->echoCLI) { echo ColorCLI::primary( 'Finished deleting '.$deleted.' parts with no binaries in '. - ($fourthQuery - $thirdQuery).' seconds.'.PHP_EOL + $fourthQuery->diffInSeconds($thirdQuery).' seconds.'.PHP_EOL ); } } // done cleaning up Binaries/Parts orphans @@ -1056,11 +1058,11 @@ public function deleteCollections($groupID): void ColorCLI::doEcho( ColorCLI::primary( 'Finished deleting '.$deleted.' collections missed after NZB creation in '. - (time() - $fourthQuery).' seconds.'.PHP_EOL. + now()->diffInSeconds($fourthQuery).' seconds.'.PHP_EOL. 'Removed '. number_format($deletedCount). ' parts/binaries/collection rows in '. - $this->consoleTools->convertTime($fourthQuery - $startTime).PHP_EOL + $fourthQuery->diffInSeconds($startTime).' seconds' ), true ); @@ -1078,7 +1080,7 @@ public function deleteCollections($groupID): void */ public function deletedReleasesByGroup($groupID = ''): void { - $startTime = time(); + $startTime = now(); $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; if ($this->echoCLI) { @@ -1157,7 +1159,7 @@ public function deletedReleasesByGroup($groupID = ''): void ' releases: '.PHP_EOL. $minSizeDeleted.' smaller than, '.$maxSizeDeleted.' bigger than, '.$minFilesDeleted. ' with less files than site/groups setting in: '. - $this->consoleTools->convertTime(time() - $startTime) + now()->diffInSeconds($startTime).' seconds' ), true ); @@ -1173,7 +1175,7 @@ public function deletedReleasesByGroup($groupID = ''): void */ public function deleteReleases(): void { - $startTime = time(); + $startTime = now(); $genres = new Genres(); $passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0; $disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0; @@ -1395,7 +1397,7 @@ public function deleteReleases(): void ColorCLI::doEcho( ColorCLI::primary( 'Removed '.number_format($totalDeleted).' releases in '. - $this->consoleTools->convertTime(time() - $startTime) + now()->diffInSeconds($startTime).' seconds' ), true ); diff --git a/Changelog b/Changelog index 77de4a15c0..561eba86be 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-09-13 DariusIII + * Chg: Use now() helper and related functions for time calculations in ProcessReleases class * Chg: Update laravel/framework to version 5.7 * Chg: Update smarty/smarty to version 3.1.33 2018-09-12 DariusIII