Skip to content

Commit

Permalink
load pieces hash skip error torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Jul 30, 2023
1 parent 98274db commit b9118ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/TorrentLoadPiecesHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle()
$rep = new TorrentRepository();
$this->info("id: $id, going to load pieces hash...");
$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;
}
}
27 changes: 16 additions & 11 deletions app/Repositories/TorrentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,17 +825,24 @@ public function loadPiecesHashCache($id = 0): int
}
$pipe = NexusDB::redis()->multi(\Redis::PIPELINE);
$piecesHashCaseWhen = $updateIdArr = [];
$count = 0;
foreach ($list as $item) {
$piecesHash = $item->pieces_hash;
if (!$piecesHash) {
$torrentFile = $torrentDir . $item->id . ".torrent";
$loadResult = Bencode::load($torrentFile);
$piecesHash = sha1($loadResult['info']['pieces']);
$piecesHashCaseWhen[] = sprintf("when %s then '%s'", $item->id, $piecesHash);
$updateIdArr[] = $item->id;
do_log(sprintf("torrent: %s no pieces hash, load from torrent file: %s, pieces hash: %s", $item->id, $torrentFile, $piecesHash));
try {
$piecesHash = $item->pieces_hash;
if (!$piecesHash) {
$torrentFile = $torrentDir . $item->id . ".torrent";
$loadResult = Bencode::load($torrentFile);
$piecesHash = sha1($loadResult['info']['pieces']);
$piecesHashCaseWhen[] = sprintf("when %s then '%s'", $item->id, $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();
if (!empty($piecesHashCaseWhen)) {
Expand All @@ -846,8 +853,6 @@ public function loadPiecesHashCache($id = 0): int
);
NexusDB::statement($sql);
}
$count = $list->count();
$total += $count;
do_log("success load page: $page, size: $size, count: $count");
$page++;
}
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
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('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down

0 comments on commit b9118ae

Please sign in to comment.