Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore broken behavior: after uploading a new torrent its tracker stats must be updated #87

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Database for MysqlDatabase {
INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id
LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id
WHERE title LIKE ?
GROUP BY torrent_id",
GROUP BY tt.torrent_id",
category_filter_query
);

Expand Down
2 changes: 1 addition & 1 deletion src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Database for SqliteDatabase {
INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id
LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id
WHERE title LIKE ?
GROUP BY ts.torrent_id",
GROUP BY tt.torrent_id",
category_filter_query
);

Expand Down
6 changes: 6 additions & 0 deletions src/routes/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ pub async fn upload_torrent(req: HttpRequest, payload: Multipart, app_data: WebA
)
.await?;

// update torrent tracker stats
let _ = app_data
.tracker
.update_torrent_tracker_stats(torrent_id, &torrent_request.torrent.info_hash())
.await;

// whitelist info hash on tracker
if let Err(e) = app_data
.tracker
Expand Down
10 changes: 8 additions & 2 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,19 @@ impl TrackerService {
}

pub async fn update_torrents(&self) -> Result<(), ServiceError> {
println!("Updating torrents..");
println!("Updating torrents ...");
let torrents = self.database.get_all_torrents_compact().await?;

for torrent in torrents {
let _ = self.get_torrent_info(torrent.torrent_id, &torrent.info_hash).await;
let _ = self
.update_torrent_tracker_stats(torrent.torrent_id, &torrent.info_hash)
.await;
}

Ok(())
}

pub async fn update_torrent_tracker_stats(&self, torrent_id: i64, info_hash: &str) -> Result<TorrentInfo, ServiceError> {
self.get_torrent_info(torrent_id, info_hash).await
}
}