load pieces hash skip error torrent

This commit is contained in:
xiaomlove
2023-07-31 01:00:59 +08:00
parent 98274dbb0d
commit b9118ae8f6
3 changed files with 18 additions and 13 deletions
@@ -33,7 +33,7 @@ class TorrentLoadPiecesHash extends Command
$rep = new TorrentRepository(); $rep = new TorrentRepository();
$this->info("id: $id, going to load pieces hash..."); $this->info("id: $id, going to load pieces hash...");
$total = $rep->loadPiecesHashCache($id); $total = $rep->loadPiecesHashCache($id);
$this->info(sprintf("total: %s, cost time: %s seconds.", $total, time() - $begin)); $this->info(sprintf("%s, total: %s, cost time: %s seconds.", nexus()->getRequestId(), $total, time() - $begin));
return Command::SUCCESS; return Command::SUCCESS;
} }
} }
+16 -11
View File
@@ -825,17 +825,24 @@ HTML;
} }
$pipe = NexusDB::redis()->multi(\Redis::PIPELINE); $pipe = NexusDB::redis()->multi(\Redis::PIPELINE);
$piecesHashCaseWhen = $updateIdArr = []; $piecesHashCaseWhen = $updateIdArr = [];
$count = 0;
foreach ($list as $item) { foreach ($list as $item) {
$piecesHash = $item->pieces_hash; try {
if (!$piecesHash) { $piecesHash = $item->pieces_hash;
$torrentFile = $torrentDir . $item->id . ".torrent"; if (!$piecesHash) {
$loadResult = Bencode::load($torrentFile); $torrentFile = $torrentDir . $item->id . ".torrent";
$piecesHash = sha1($loadResult['info']['pieces']); $loadResult = Bencode::load($torrentFile);
$piecesHashCaseWhen[] = sprintf("when %s then '%s'", $item->id, $piecesHash); $piecesHash = sha1($loadResult['info']['pieces']);
$updateIdArr[] = $item->id; $piecesHashCaseWhen[] = sprintf("when %s then '%s'", $item->id, $piecesHash);
do_log(sprintf("torrent: %s no pieces hash, load from torrent file: %s, pieces hash: %s", $item->id, $torrentFile, $piecesHash)); $updateIdArr[] = $item->id;
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++;
} catch (\Exception $exception) {
do_log(sprintf("load pieces hash of torrent: %s error: %s", $item->id, $exception->getMessage()), 'error');
} }
$pipe->hSet(self::PIECES_HASH_CACHE_KEY, $piecesHash, $this->buildPiecesHashCacheValue($item->id, $piecesHash));
} }
$pipe->exec(); $pipe->exec();
if (!empty($piecesHashCaseWhen)) { if (!empty($piecesHashCaseWhen)) {
@@ -846,8 +853,6 @@ HTML;
); );
NexusDB::statement($sql); NexusDB::statement($sql);
} }
$count = $list->count();
$total += $count;
do_log("success load page: $page, size: $size, count: $count"); do_log("success load page: $page, size: $size, count: $count");
$page++; $page++;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.6'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.6');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-07-30'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-07-31');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");