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