Skip to content

Commit

Permalink
Use now() helper and related functions for time calculations in Proce…
Browse files Browse the repository at this point in the history
…ssReleases class
  • Loading branch information
DariusIII committed Sep 13, 2018
1 parent 11dd795 commit 63ea968
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
58 changes: 30 additions & 28 deletions Blacklight/processing/ProcessReleases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
);
Expand All @@ -331,7 +333,7 @@ public function processIncompleteCollections($groupID): void
*/
public function processCollectionSizes($groupID): void
{
$startTime = time();
$startTime = now();
$this->initiateTableNames($groupID);

if ($this->echoCLI) {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -377,7 +379,7 @@ public function processCollectionSizes($groupID): void
*/
public function deleteUnwantedCollections($groupID): void
{
$startTime = time();
$startTime = now();
$this->initiateTableNames($groupID);

if ($this->echoCLI) {
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -533,7 +535,7 @@ protected function formFromNamesQuery(): void
*/
public function createReleases($groupID): array
{
$startTime = time();
$startTime = now();
$this->initiateTableNames($groupID);

$categorize = new Categorize();
Expand Down Expand Up @@ -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
);
Expand All @@ -735,7 +737,7 @@ public function createReleases($groupID): array
*/
public function createNZBs($groupID): int
{
$startTime = time();
$startTime = now();
$this->formFromNamesQuery();

if ($this->echoCLI) {
Expand Down Expand Up @@ -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
);
Expand All @@ -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.');
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -858,7 +860,7 @@ public function postProcessReleases($postProcess, &$nntp): void
*/
public function deleteCollections($groupID): void
{
$startTime = time();
$startTime = now();
$this->initiateTableNames($groupID);

$deletedCount = 0;
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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.'
);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
);
Expand All @@ -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) {
Expand Down Expand Up @@ -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
);
Expand All @@ -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;
Expand Down Expand Up @@ -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
);
Expand Down
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 63ea968

Please sign in to comment.