diff --git a/app/Console/Commands/TorrentLoadPiecesHash.php b/app/Console/Commands/TorrentLoadPiecesHash.php index a7f76183..5e02393f 100644 --- a/app/Console/Commands/TorrentLoadPiecesHash.php +++ b/app/Console/Commands/TorrentLoadPiecesHash.php @@ -32,8 +32,8 @@ class TorrentLoadPiecesHash extends Command $id = $this->option('id'); $rep = new TorrentRepository(); $this->info("id: $id, going to load pieces hash..."); - $total = $rep->loadPiecesHashCache($id); - $this->info(sprintf("%s, total: %s, cost time: %s seconds.", nexus()->getRequestId(), $total, time() - $begin)); + $result = $rep->loadPiecesHashCache($id); + $this->info(sprintf("%s, result: %s, cost time: %s seconds.", nexus()->getRequestId(), json_encode($result), time() - $begin)); return Command::SUCCESS; } } diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 8fbcf304..f82d8cab 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -35,6 +35,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Nexus\Database\NexusDB; use Rhilip\Bencode\Bencode; +use function Sodium\compare; class TorrentRepository extends BaseRepository { @@ -803,7 +804,7 @@ HTML; return $out; } - public function loadPiecesHashCache($id = 0): int + public function loadPiecesHashCache($id = 0): array { $page = 1; $size = 1000; @@ -811,7 +812,7 @@ HTML; if ($id) { $query = $query->whereIn("id", Arr::wrap($id)); } - $total = 0; + $total = $success = 0; $torrentDir = sprintf( "%s/%s/", rtrim(ROOT_PATH, '/'), @@ -825,8 +826,9 @@ HTML; } $pipe = NexusDB::redis()->multi(\Redis::PIPELINE); $piecesHashCaseWhen = $updateIdArr = []; - $count = 0; + $currentCount = 0; foreach ($list as $item) { + $total++; try { $piecesHash = $item->pieces_hash; if (!$piecesHash) { @@ -838,8 +840,8 @@ HTML; do_log(sprintf("torrent: %s no pieces hash, load from torrent file: %s, pieces hash: %s", $item->id, $torrentFile, $piecesHash)); } $pipe->hSet(self::PIECES_HASH_CACHE_KEY, $piecesHash, $this->buildPiecesHashCacheValue($item->id, $piecesHash)); - $total++; - $count++; + $success++; + $currentCount++; } catch (\Exception $exception) { do_log(sprintf("load pieces hash of torrent: %s error: %s", $item->id, $exception->getMessage()), 'error'); } @@ -853,11 +855,11 @@ HTML; ); NexusDB::statement($sql); } - do_log("success load page: $page, size: $size, count: $count"); + do_log("success load page: $page, size: $size, count: $currentCount"); $page++; } - do_log("[DONE], total: $total"); - return $total; + do_log("[DONE], total: $total, success: $success"); + return compact('total', 'success'); } }