Skip to content

Commit

Permalink
add: custom schema changes
Browse files Browse the repository at this point in the history
Add:

- `users.is_donor`
- `users.is_lifetime`

Co-authored-by: HDVinnie <hdinnovations@protonmail.com>
  • Loading branch information
Roardom and HDVinnie committed Nov 24, 2024
1 parent 6367f8c commit e9b849f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ pub async fn announce(
_ => (),
}

// Make sure user isn't leeching more torrents than their group allows
// Make sure user isn't leeching more torrents than their group allows unless they are a lifetime user
let has_hit_download_slot_limit = queries.left > 0
&& !user.is_lifetime
&& matches!(group.download_slots, Some(slots) if slots <= user.num_leeching);

// Change of upload/download compared to previous announce
Expand Down Expand Up @@ -760,6 +761,7 @@ pub async fn announce(
.featured_torrents
.read()
.contains(&FeaturedTorrent { torrent_id })
|| user.is_donor
{
0
} else {
Expand Down Expand Up @@ -827,7 +829,7 @@ pub async fn announce(
user_agent: String::from(user_agent),
is_active: queries.event != Event::Stopped,
is_seeder: queries.left == 0,
is_immune: group.is_immune,
is_immune: group.is_immune || user.is_donor,
uploaded: queries.uploaded,
downloaded: queries.downloaded,
uploaded_delta,
Expand Down
14 changes: 13 additions & 1 deletion src/tracker/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl Map {
users.passkey as `passkey: Passkey`,
users.can_download as `can_download: bool`,
CAST(COALESCE(SUM(peers.seeder = 1 AND peers.active = 1 AND peers.visible = 1), 0) AS UNSIGNED) as `num_seeding: u32`,
CAST(COALESCE(SUM(peers.seeder = 0 AND peers.active = 1 AND peers.visible = 1), 0) AS UNSIGNED) as `num_leeching: u32`
CAST(COALESCE(SUM(peers.seeder = 0 AND peers.active = 1 AND peers.visible = 1), 0) AS UNSIGNED) as `num_leeching: u32`,
users.is_donor as `is_donor: bool`,
users.is_lifetime as `is_lifetime: bool`
FROM
users
LEFT JOIN
Expand Down Expand Up @@ -69,6 +71,8 @@ impl Map {
num_leeching: user.num_leeching,
receive_seed_list_rates: config.user_receive_seed_list_rate_limits.clone(),
receive_leech_list_rates: config.user_receive_leech_list_rate_limits.clone(),
is_donor: user.is_donor,
is_lifetime: user.is_lifetime,
},
);
}
Expand Down Expand Up @@ -101,6 +105,8 @@ impl Map {
can_download: user.can_download,
num_seeding: user.num_seeding,
num_leeching: user.num_leeching,
is_donor: user.is_donor,
is_lifetime: user.is_lifetime,
receive_seed_list_rates,
receive_leech_list_rates,
},
Expand Down Expand Up @@ -165,6 +171,8 @@ pub struct DBImportUser {
pub can_download: bool,
pub num_seeding: u32,
pub num_leeching: u32,
pub is_donor: bool,
pub is_lifetime: bool,
}

#[derive(Clone, Deserialize, Serialize)]
Expand All @@ -175,6 +183,8 @@ pub struct User {
pub can_download: bool,
pub num_seeding: u32,
pub num_leeching: u32,
pub is_donor: bool,
pub is_lifetime: bool,
pub receive_seed_list_rates: RateCollection,
pub receive_leech_list_rates: RateCollection,
}
Expand All @@ -187,6 +197,8 @@ pub struct APIInsertUser {
pub can_download: bool,
pub num_seeding: u32,
pub num_leeching: u32,
pub is_donor: bool,
pub is_lifetime: bool,
}

#[derive(Clone, Deserialize, Hash)]
Expand Down

0 comments on commit e9b849f

Please sign in to comment.