fix scrape totals, reset counters on zero results

This commit is contained in:
ghost 2023-10-09 05:36:49 +03:00
parent 1be80ca34e
commit 68fdc3c28c

View File

@ -67,6 +67,11 @@ class TorrentService
$hashes[] = $hash; $hashes[] = $hash;
} }
// Init default values
$seeders = 0;
$peers = 0;
$leechers = 0;
// Get scrape // Get scrape
if ($hashes && $trackers) if ($hashes && $trackers)
{ {
@ -77,29 +82,35 @@ class TorrentService
{ {
if (isset($result['seeders'])) if (isset($result['seeders']))
{ {
$torrent->setSeeders( $seeders = $seeders + (int) $result['seeders'];
(int) $result['seeders']
);
} }
if (isset($result['completed'])) if (isset($result['completed']))
{ {
$torrent->setPeers( $peers = $peers + (int) $result['completed'];
(int) $result['completed']
);
} }
if (isset($result['leechers'])) if (isset($result['leechers']))
{ {
$torrent->setLeechers( $leechers = $leechers + (int) $result['leechers'];
(int) $result['leechers']
);
} }
} }
} }
} }
// Update time scraped // Update torrent scrape
$torrent->setSeeders(
$seeders
);
$torrent->setPeers(
$peers
);
$torrent->setLeechers(
$leechers
);
$torrent->setScraped( $torrent->setScraped(
time() time()
); );