diff --git a/include/functions.php b/include/functions.php index 240bd282..be9b623d 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2553,12 +2553,12 @@ else { //// check every 60 seconds ////////////////// $activeseed = $Cache->get_value('user_'.$CURUSER["id"].'_active_seed_count'); if ($activeseed == ""){ - $activeseed = count_peer(sprintf("userid = %s and seeder = 'yes'", $CURUSER['id'])); + $activeseed = count_peer(sprintf("userid = %s and seeder = 'yes'", $CURUSER['id']), 'torrent'); $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'])); + $activeleech = count_peer(sprintf("userid = %s and seeder = 'no'", $CURUSER['id']), 'torrent'); $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 befde0a0..de655361 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -705,20 +705,20 @@ function isIPV6 ($ip) return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } -function count_peer($whereStr) +function count_peer($whereStr, $field = 'peer_id') { if (empty($whereStr)) { throw new \InvalidArgumentException("require whereStr"); } if (IN_NEXUS) { - $sql = "select count(distinct(peer_id)) as counts from peers where $whereStr"; + $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(peer_id)) as counts") + ->selectRaw("count(distinct($field)) as counts") ->first(); return $res->counts; } diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index 6f4423fb..0d0b21a9 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.peer_id 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' group by peers.torrent 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.peer_id 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' group by peers.torrent ORDER BY torrents.added DESC") or sqlerr(); $count = mysql_num_rows($res); if ($count > 0){ list($torrentlist, $total_size) = maketable ( $res, 'leeching' );