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 Jul 14, 2024
1 parent 9a5b912 commit 7493ed1
Show file tree
Hide file tree
Showing 2 changed files with 13 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 @@ -381,8 +381,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 @@ -711,6 +712,7 @@ pub async fn announce(
.featured_torrents
.read()
.contains(&FeaturedTorrent { torrent_id })
|| user.is_donor
{
0
} else {
Expand Down Expand Up @@ -768,7 +770,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
10 changes: 9 additions & 1 deletion src/tracker/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -78,6 +80,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,
},
);

Expand Down Expand Up @@ -140,6 +144,8 @@ pub struct User {
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 All @@ -150,6 +156,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 7493ed1

Please sign in to comment.