diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index a9595cc4..aa75e864 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -770,9 +770,16 @@ class TrackerRepository extends BaseRepository do_log("no event, return", 'debug'); return; } - $torrentId = $torrent->id; - $torrent->seeders = count_peer("torrent = $torrentId and to_go = 0"); - $torrent->leechers = count_peer("torrent = $torrentId and to_go > 0"); + $torrent->seeders = Peer::query() + ->where('torrent', $torrent->id) + ->where('to_go', '=',0) + ->count(); + + $torrent->leechers = Peer::query() + ->where('torrent', $torrent->id) + ->where('to_go', '>', 0) + ->count(); + $torrent->visible = Torrent::VISIBLE_YES; $torrent->last_action = Carbon::now(); diff --git a/include/constants.php b/include/constants.php index 42486d09..ccc94406 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ get_value('user_'.$CURUSER["id"].'_active_seed_count'); if ($activeseed == ""){ - $activeseed = count_peer(sprintf("userid = %s and seeder = 'yes'", $CURUSER['id']), 'torrent'); + $activeseed = get_row_count("peers","WHERE userid=" . sqlesc($CURUSER["id"]) . " AND seeder='yes'"); $Cache->cache_value('user_'.$CURUSER["id"].'_active_seed_count', $activeseed, 60); } $activeleech = $Cache->get_value('user_'.$CURUSER["id"].'_active_leech_count'); if ($activeleech == ""){ - $activeleech = count_peer(sprintf("userid = %s and seeder = 'no'", $CURUSER['id']), 'torrent'); + $activeleech = get_row_count("peers","WHERE userid=" . sqlesc($CURUSER["id"]) . " AND seeder='no'"); $Cache->cache_value('user_'.$CURUSER["id"].'_active_leech_count', $activeleech, 60); } $unread = $Cache->get_value('user_'.$CURUSER["id"].'_unread_message_count'); diff --git a/include/globalfunctions.php b/include/globalfunctions.php index fa559307..f38c25a9 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -704,22 +704,3 @@ function isIPV6 ($ip) { return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } - -function count_peer($whereStr, $field = 'peer_id') -{ - if (empty($whereStr)) { - throw new \InvalidArgumentException("require whereStr"); - } - if (IN_NEXUS) { - $sql = "select count(distinct($field)) as counts from peers where $whereStr"; - $res = sql_query($sql); - $count = mysql_fetch_assoc($res); - return $count['counts']; - } else { - $res = \Illuminate\Support\Facades\DB::table('peers') - ->whereRaw($whereStr) - ->selectRaw("count(distinct($field)) as counts") - ->first(); - return $res->counts; - } -} diff --git a/public/announce.php b/public/announce.php index 13812478..d5030a9a 100644 --- a/public/announce.php +++ b/public/announce.php @@ -512,8 +512,8 @@ else } if (isset($event) && !empty($event)) { - $updateset[] = 'seeders = ' . count_peer("torrent = $torrentid and to_go = 0"); - $updateset[] = 'leechers = ' . count_peer("torrent = $torrentid and to_go > 0"); + $updateset[] = 'seeders = ' . get_row_count("peers", "where torrent = $torrentid and to_go = 0"); + $updateset[] = 'leechers = ' . get_row_count("peers", "where torrent = $torrentid and to_go > 0"); } if (count($updateset)) // Update only when there is change in peer counts diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index 0d0b21a9..ba9a7813 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -195,7 +195,7 @@ switch ($type) // Current Seeding case 'seeding': { - $res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' group by peers.torrent ORDER BY torrents.added DESC") or sqlerr(); + $res = sql_query("SELECT torrent,added,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='yes' ORDER BY torrents.added DESC") or sqlerr(); $count = mysql_num_rows($res); if ($count > 0){ list($torrentlist, $total_size) = maketable ( $res, 'seeding' ); @@ -206,7 +206,7 @@ switch ($type) // Current Leeching case 'leeching': { - $res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' group by peers.torrent ORDER BY torrents.added DESC") or sqlerr(); + $res = sql_query("SELECT torrent,snatched.uploaded,snatched.downloaded,torrents.name as torrentname, torrents.small_descr, torrents.sp_state, categories.name as catname,size,torrents.hr,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN snatched ON torrents.id = snatched.torrentid WHERE peers.userid=$id AND snatched.userid = $id AND peers.seeder='no' ORDER BY torrents.added DESC") or sqlerr(); $count = mysql_num_rows($res); if ($count > 0){ list($torrentlist, $total_size) = maketable ( $res, 'leeching' ); diff --git a/public/viewpeerlist.php b/public/viewpeerlist.php index 6f658825..c531cc32 100644 --- a/public/viewpeerlist.php +++ b/public/viewpeerlist.php @@ -93,7 +93,7 @@ function dltable($name, $arr, $torrent) } $downloaders = array(); $seeders = array(); - $subres = sql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ip, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id group by peer_id ") or sqlerr(); + $subres = sql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ip, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr(); while ($subrow = mysql_fetch_array($subres)) { if ($subrow["seeder"] == "yes") $seeders[] = $subrow;