Thread: Cleanup
View Single Post
  #1  
Old 30th March 2021, 21:37
xblade's Avatar
xblade xblade is offline
Cod3r
 
Join Date: Nov 2020
P2P
Posts: 239
Thumbs up Cleanup
ive just updated to Debian 9 everything works ok but the clean up of torrent seeders ...seeds are there till it runs the clean up loose the seeds on seedbox and home pc..into 2 min after clean torrents are back any help would be nice


Code:
    $torrents = array();
    $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder");
    while ($row = mysqli_fetch_assoc($res)) {
        if ($row["seeder"] == "yes")
            $key = "seeders";
        else
            $key = "leechers";
        $torrents[$row["torrent"]][$key] = $row["c"];
    }

    $res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent");
    while ($row = mysqli_fetch_assoc($res)) {
        $torrents[$row["torrent"]]["comments"] = $row["c"];
    }

    $fields = explode(":", "comments:leechers:seeders");
    $res = sql_query("SELECT id, seeders, leechers, comments FROM torrents");
    while ($row = mysqli_fetch_assoc($res)) {
        $id = $row["id"];
        $torr = $torrents[$id];
        foreach ($fields as $field) {
            if (!isset($torr[$field]))
                $torr[$field] = 0;
        }
        $update = array();
        foreach ($fields as $field) {
            if ($torr[$field] != $row[$field])
                $update[] = "$field = " . $torr[$field];
        }
        if (count($update))
            sql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id");
    }
Reply With Quote