Skip to content

Commit

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

- `torrents.deleted_at`
- `users.is_donor`
- `users.is_lifetime`

Co-authored-by: HDVinnie <hdinnovations@protonmail.com>
  • Loading branch information
Roardom and HDVinnie committed May 28, 2024
1 parent 30b9efb commit 3247a6b
Show file tree
Hide file tree
Showing 5 changed files with 19 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 @@ -358,8 +358,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 @@ -663,6 +664,7 @@ pub async fn announce(
.featured_torrents
.read()
.contains(&FeaturedTorrent { torrent_id })
|| user.is_donor
{
0
} else {
Expand Down Expand Up @@ -725,7 +727,7 @@ pub async fn announce(
queries.downloaded,
queries.left == 0,
queries.event != Event::Stopped,
group.is_immune,
group.is_immune || user.is_donor,
completed_at,
);

Expand Down
2 changes: 2 additions & 0 deletions src/scheduler/torrent_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl Queue {
.await
.map(|result| result.rows_affected());

/*
if rows_affected_res.is_ok() {
// When torrent records are upserted after they have been deleted
// since the last flush interval, the record gets unintentionally
Expand All @@ -166,6 +167,7 @@ impl Queue {
.execute(db)
.await;
}
*/

rows_affected_res
}
Expand Down
2 changes: 2 additions & 0 deletions src/tracker/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ impl Map {
0 as `is_deleted: bool`
FROM
torrents
WHERE
torrents.deleted_at IS NULL
"#
)
.fetch_all(db)
Expand Down
2 changes: 2 additions & 0 deletions src/tracker/torrent/infohash2id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl Map {
torrents.info_hash as `info_hash: InfoHash`
FROM
torrents
WHERE
torrents.deleted_at IS NULL
"#
)
.fetch_all(db)
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 3247a6b

Please sign in to comment.