Skip to content

Commit

Permalink
fix: [#84] restore behavior. Update torrent stats after upload
Browse files Browse the repository at this point in the history
When a new torrent is uploaded we have to update the tracker torrent
stats in the `torrust_torrent_tracker_stats` table.

It was from the UI but not for the DB migration script becuase the
frontend makes a request to get the torrent info after the upload and
that endpint updates the torrent tracket stats.

It must update the stats even if that endpoint is not called after
uploading a new torrent.
  • Loading branch information
josecelano committed Nov 30, 2022
1 parent 59b1ea8 commit c291557
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
}
}

0 comments on commit c291557

Please sign in to comment.