Skip to content

Commit c291557

Browse files
committed
fix: [#84] restore behavior. Update torrent stats after upload
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.
1 parent 59b1ea8 commit c291557

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/routes/torrent.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ pub async fn upload_torrent(req: HttpRequest, payload: Multipart, app_data: WebA
9696
)
9797
.await?;
9898

99+
// update torrent tracker stats
100+
let _ = app_data
101+
.tracker
102+
.update_torrent_tracker_stats(torrent_id, &torrent_request.torrent.info_hash())
103+
.await;
104+
99105
// whitelist info hash on tracker
100106
if let Err(e) = app_data
101107
.tracker

src/tracker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,19 @@ impl TrackerService {
179179
}
180180

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

185185
for torrent in torrents {
186-
let _ = self.get_torrent_info(torrent.torrent_id, &torrent.info_hash).await;
186+
let _ = self
187+
.update_torrent_tracker_stats(torrent.torrent_id, &torrent.info_hash)
188+
.await;
187189
}
188190

189191
Ok(())
190192
}
193+
194+
pub async fn update_torrent_tracker_stats(&self, torrent_id: i64, info_hash: &str) -> Result<TorrentInfo, ServiceError> {
195+
self.get_torrent_info(torrent_id, info_hash).await
196+
}
191197
}

0 commit comments

Comments
 (0)