mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
load pieces hash return total and success
This commit is contained in:
@@ -32,8 +32,8 @@ class TorrentLoadPiecesHash extends Command
|
|||||||
$id = $this->option('id');
|
$id = $this->option('id');
|
||||||
$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);
|
$result = $rep->loadPiecesHashCache($id);
|
||||||
$this->info(sprintf("%s, total: %s, cost time: %s seconds.", nexus()->getRequestId(), $total, time() - $begin));
|
$this->info(sprintf("%s, result: %s, cost time: %s seconds.", nexus()->getRequestId(), json_encode($result), time() - $begin));
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Nexus\Database\NexusDB;
|
use Nexus\Database\NexusDB;
|
||||||
use Rhilip\Bencode\Bencode;
|
use Rhilip\Bencode\Bencode;
|
||||||
|
use function Sodium\compare;
|
||||||
|
|
||||||
class TorrentRepository extends BaseRepository
|
class TorrentRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
@@ -803,7 +804,7 @@ HTML;
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadPiecesHashCache($id = 0): int
|
public function loadPiecesHashCache($id = 0): array
|
||||||
{
|
{
|
||||||
$page = 1;
|
$page = 1;
|
||||||
$size = 1000;
|
$size = 1000;
|
||||||
@@ -811,7 +812,7 @@ HTML;
|
|||||||
if ($id) {
|
if ($id) {
|
||||||
$query = $query->whereIn("id", Arr::wrap($id));
|
$query = $query->whereIn("id", Arr::wrap($id));
|
||||||
}
|
}
|
||||||
$total = 0;
|
$total = $success = 0;
|
||||||
$torrentDir = sprintf(
|
$torrentDir = sprintf(
|
||||||
"%s/%s/",
|
"%s/%s/",
|
||||||
rtrim(ROOT_PATH, '/'),
|
rtrim(ROOT_PATH, '/'),
|
||||||
@@ -825,8 +826,9 @@ HTML;
|
|||||||
}
|
}
|
||||||
$pipe = NexusDB::redis()->multi(\Redis::PIPELINE);
|
$pipe = NexusDB::redis()->multi(\Redis::PIPELINE);
|
||||||
$piecesHashCaseWhen = $updateIdArr = [];
|
$piecesHashCaseWhen = $updateIdArr = [];
|
||||||
$count = 0;
|
$currentCount = 0;
|
||||||
foreach ($list as $item) {
|
foreach ($list as $item) {
|
||||||
|
$total++;
|
||||||
try {
|
try {
|
||||||
$piecesHash = $item->pieces_hash;
|
$piecesHash = $item->pieces_hash;
|
||||||
if (!$piecesHash) {
|
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));
|
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));
|
$pipe->hSet(self::PIECES_HASH_CACHE_KEY, $piecesHash, $this->buildPiecesHashCacheValue($item->id, $piecesHash));
|
||||||
$total++;
|
$success++;
|
||||||
$count++;
|
$currentCount++;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
do_log(sprintf("load pieces hash of torrent: %s error: %s", $item->id, $exception->getMessage()), 'error');
|
do_log(sprintf("load pieces hash of torrent: %s error: %s", $item->id, $exception->getMessage()), 'error');
|
||||||
}
|
}
|
||||||
@@ -853,11 +855,11 @@ HTML;
|
|||||||
);
|
);
|
||||||
NexusDB::statement($sql);
|
NexusDB::statement($sql);
|
||||||
}
|
}
|
||||||
do_log("success load page: $page, size: $size, count: $count");
|
do_log("success load page: $page, size: $size, count: $currentCount");
|
||||||
$page++;
|
$page++;
|
||||||
}
|
}
|
||||||
do_log("[DONE], total: $total");
|
do_log("[DONE], total: $total, success: $success");
|
||||||
return $total;
|
return compact('total', 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user