From 339f0ef9482de175909b680f53e37e3179fa0ec9 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Thu, 7 Sep 2023 00:44:28 +0700 Subject: [PATCH] Minor improvements (#889) --- bt/announce.php | 20 ++++++++++---------- common.php | 1 - library/attach_mod/displaying_torrent.php | 2 +- library/config.php | 1 + src/Legacy/Cache/Memcache.php | 4 ++-- src/Legacy/Cache/Redis.php | 10 ++++++---- src/Legacy/Datastore/Memcache.php | 4 ++-- src/Legacy/Datastore/Redis.php | 4 ++-- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index 1bccc6dca..06244a5f6 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -25,10 +25,10 @@ if (isset($_GET['event']) && $_GET['event'] === 'completed') { $announce_interval = $bb_cfg['announce_interval']; $passkey_key = $bb_cfg['passkey_key']; -$max_left_val = 536870912000; // 500 GB -$max_up_down_val = 5497558138880; // 5 TB -$max_up_add_val = 85899345920; // 80 GB -$max_down_add_val = 85899345920; // 80 GB +$max_left_val = 536870912000; // 500 GB +$max_up_down_val = 5497558138880; // 5 TB +$max_up_add_val = 85899345920; // 80 GB +$max_down_add_val = 85899345920; // 80 GB // Recover info_hash if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) { @@ -139,7 +139,7 @@ function drop_fast_announce($lp_info) global $announce_interval; if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) { - return; // if announce interval correct + return; // if announce interval correct } $new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW; @@ -163,6 +163,7 @@ require __DIR__ . '/includes/init_tr.php'; $seeder = ($left == 0) ? 1 : 0; $stopped = ($event === 'stopped'); +$completed = ($event === 'completed'); // Stopped event if ($stopped) { @@ -244,7 +245,7 @@ if ($lp_info) { if (!$seeder && $bb_cfg['tracker']['leech_expire_factor'] && $user_ratio < 0.5) { $sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']); } - $sql .= " GROUP BY user_id"; + $sql .= " GROUP BY user_id"; if ($row = DB()->fetch_row($sql)) { if ($seeder && $bb_cfg['tracker']['limit_seed_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_seed_count']) { @@ -267,7 +268,7 @@ if ($lp_info) { if (!$seeder && $bb_cfg['tracker']['leech_expire_factor']) { $sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']); } - $sql .= " GROUP BY topic_id"; + $sql .= " GROUP BY topic_id"; if ($row = DB()->fetch_row($sql)) { if ($seeder && $bb_cfg['tracker']['limit_seed_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_seed_ips']) { @@ -342,7 +343,7 @@ if ($lp_info) { } if (!$lp_info || !$peer_info_updated) { - $columns = 'peer_hash, topic_id, user_id, ip, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time'; + $columns = 'peer_hash, topic_id, user_id, ip, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time'; $values = "'$peer_hash', $topic_id, $user_id, '$ip_sql', $port, $seeder, $releaser, $tor_type, $uploaded, $downloaded, $left, $speed_up, $speed_down, $up_add, $down_add, $update_time"; DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)"); @@ -397,8 +398,7 @@ if (!$output) { } } - $seeders = 0; - $leechers = 0; + $seeders = $leechers = 0; if ($bb_cfg['tracker']['scrape']) { $row = DB()->fetch_row(" diff --git a/common.php b/common.php index 1772762a5..e3e3e8386 100644 --- a/common.php +++ b/common.php @@ -103,7 +103,6 @@ define('BB_BT_TRACKER_SNAP', 'bb_bt_tracker_snap'); define('BB_BT_USERS', 'bb_bt_users'); define('BT_AUTH_KEY_LENGTH', 10); - define('PEER_HASH_PREFIX', 'peer_'); define('PEERS_LIST_PREFIX', 'peers_list_'); define('PEER_HASH_EXPIRE', round($bb_cfg['announce_interval'] * (0.85 * $bb_cfg['tracker']['expire_factor']))); // sec diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 8ee2fd81e..3ee2ff185 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -232,7 +232,7 @@ if ($tor_reged && $tor_info) { 'TOR_SIZE' => humn_size($tor_size), 'TOR_LONGEVITY' => delta_time($tor_info['reg_time']), - 'TOR_COMPLETED' => declension($tor_info['complete_count'], 'times'), + 'TOR_COMPLETED' => declension((int)$tor_info['complete_count'], 'times'), ]); } diff --git a/library/config.php b/library/config.php index aea7df96c..3152d023d 100644 --- a/library/config.php +++ b/library/config.php @@ -66,6 +66,7 @@ $bb_cfg['cache'] = [ 'redis' => [ 'host' => '127.0.0.1', 'port' => 6379, + 'pconnect' => true, 'con_required' => true, ], // Available cache types: filecache, memcache, sqlite, redis, apcu (filecache by default) diff --git a/src/Legacy/Cache/Memcache.php b/src/Legacy/Cache/Memcache.php index 16573aad5..6b8068b74 100644 --- a/src/Legacy/Cache/Memcache.php +++ b/src/Legacy/Cache/Memcache.php @@ -27,7 +27,7 @@ class Memcache extends Common public function __construct($cfg, $prefix = null) { if (!$this->is_installed()) { - die('Error: Memcached extension not installed'); + die("Error: $this->engine extension not installed"); } $this->cfg = $cfg; @@ -48,7 +48,7 @@ class Memcache extends Common } if (!$this->connected && $this->cfg['con_required']) { - die('Could not connect to memcached server'); + die("Could not connect to $this->engine server"); } $this->debug('stop'); diff --git a/src/Legacy/Cache/Redis.php b/src/Legacy/Cache/Redis.php index 6e6e37c16..6ea451389 100644 --- a/src/Legacy/Cache/Redis.php +++ b/src/Legacy/Cache/Redis.php @@ -27,7 +27,7 @@ class Redis extends Common public function __construct($cfg, $prefix = null) { if (!$this->is_installed()) { - die('Error: Redis extension not installed'); + die("Error: $this->engine extension not installed"); } $this->cfg = $cfg; @@ -38,15 +38,17 @@ class Redis extends Common public function connect() { - $this->cur_query = 'connect ' . $this->cfg['host'] . ':' . $this->cfg['port']; + $connect_type = ($this->cfg['pconnect']) ? 'pconnect' : 'connect'; + + $this->cur_query = $connect_type . ' ' . $this->cfg['host'] . ':' . $this->cfg['port']; $this->debug('start'); - if (@$this->redis->connect($this->cfg['host'], $this->cfg['port'])) { + if (@$this->redis->$connect_type($this->cfg['host'], $this->cfg['port'])) { $this->connected = true; } if (!$this->connected && $this->cfg['con_required']) { - die('Could not connect to redis server'); + die("Could not connect to $this->engine server"); } $this->debug('stop'); diff --git a/src/Legacy/Datastore/Memcache.php b/src/Legacy/Datastore/Memcache.php index 3214089e0..a1112d067 100644 --- a/src/Legacy/Datastore/Memcache.php +++ b/src/Legacy/Datastore/Memcache.php @@ -26,7 +26,7 @@ class Memcache extends Common public function __construct($cfg, $prefix = null) { if (!$this->is_installed()) { - die('Error: Memcached extension not installed'); + die("Error: $this->engine extension not installed"); } $this->cfg = $cfg; @@ -47,7 +47,7 @@ class Memcache extends Common } if (!$this->connected && $this->cfg['con_required']) { - die('Could not connect to memcached server'); + die("Could not connect to $this->engine server"); } $this->debug('stop'); diff --git a/src/Legacy/Datastore/Redis.php b/src/Legacy/Datastore/Redis.php index c67c57d76..ed6224ed4 100644 --- a/src/Legacy/Datastore/Redis.php +++ b/src/Legacy/Datastore/Redis.php @@ -26,7 +26,7 @@ class Redis extends Common public function __construct($cfg, $prefix = null) { if (!$this->is_installed()) { - die('Error: Redis extension not installed'); + die("Error: $this->engine extension not installed"); } $this->cfg = $cfg; @@ -45,7 +45,7 @@ class Redis extends Common } if (!$this->connected && $this->cfg['con_required']) { - die('Could not connect to redis server'); + die("Could not connect to $this->engine server"); } $this->debug('stop');