Use one variable to determine update status for hybrids

This commit is contained in:
Constantine Kovalensky 2023-11-16 10:01:18 +04:00
commit 6454b8652c

View file

@ -162,8 +162,7 @@ if ($lp_info) {
$topic_id = $lp_info['topic_id']; $topic_id = $lp_info['topic_id'];
$releaser = $lp_info['releaser']; $releaser = $lp_info['releaser'];
$tor_type = $lp_info['tor_type']; $tor_type = $lp_info['tor_type'];
$is_hybrid = $lp_info['hybrid_info']['is_hybrid'] ?? 0; $hybrid_unrecord = $lp_info['hybrid_unrecord'] ?? false;
$update_hybrid = $lp_info['hybrid_info']['update_hybrid'] ?? 0;
} else { } else {
$info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
/** /**
@ -198,9 +197,8 @@ if ($lp_info) {
// Check hybrid status // Check hybrid status
if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) { if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) {
$is_hybrid = true; if ($info_hash !== $row['info_hash']) { // Change this to substr($row['info_hash_v2'], 0, 20) in the future for updating statistics, in case of v2 torrents being prioritized.
if ($info_hash === $row['info_hash']) { // Change this to substr($row['info_hash_v2'], 0, 20) in the future for updating statistics, in case of v2 torrents being prioritized. $hybrid_unrecord = true; // This allows us to announce only for one info-hash
$update_hybrid = true;
} }
} }
@ -301,8 +299,8 @@ if ($bb_cfg['tracker']['freeleech'] && $down_add) {
// Insert / update peer info // Insert / update peer info
$peer_info_updated = false; $peer_info_updated = false;
$update_time = ($stopped) ? 0 : TIMENOW; $update_time = ($stopped) ? 0 : TIMENOW;
if (empty($is_hybrid) || !empty($update_hybrid)) { // Record statistics only for one topic
if ($lp_info) { if ($lp_info && empty($hybrid_unrecord)) {
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time"; $sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
$sql .= ", $ip_version = '$ip_sql'"; $sql .= ", $ip_version = '$ip_sql'";
@ -331,17 +329,17 @@ if (empty($is_hybrid) || !empty($update_hybrid)) { // Record statistics only for
DB()->query($sql); DB()->query($sql);
$peer_info_updated = DB()->affected_rows(); $peer_info_updated = DB()->affected_rows();
} }
if ((!$lp_info || !$peer_info_updated) && !$stopped) { if ((!$lp_info || !$peer_info_updated) && !$stopped && empty($hybrid_unrecord)) {
$columns = "peer_hash, topic_id, user_id, $ip_version, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time, complete, peer_id"; $columns = "peer_hash, topic_id, user_id, $ip_version, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time, complete, peer_id";
$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, $complete, '$peer_id_sql'"; $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, $complete, '$peer_id_sql'";
DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)"); DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)");
}
} }
// Exit if stopped // Exit if stopped
if ($stopped) { if ($stopped) {
silent_exit('Cache will be reset within 30 seconds'); silent_exit('Cache will be reset within 30 seconds');
@ -362,11 +360,8 @@ $lp_info_new = [
'ip_ver6' => $lp_info['ip_ver6'] ?? $ipv6, 'ip_ver6' => $lp_info['ip_ver6'] ?? $ipv6,
]; ];
if (!empty($is_hybrid)) { if (!empty($hybrid_unrecord)) {
$lp_info_new['hybrid_info'] = [ $lp_info_new['hybrid_unrecord'] = $hybrid_unrecord;
'is_hybrid' => $lp_info['hybrid_info']['is_hybrid'] ?? isset($is_hybrid),
'update_hybrid' => $lp_info['hybrid_info']['update_hybrid'] ?? isset($update_hybrid)
];
} }
// Cache new list with peer hash // Cache new list with peer hash