@@ -41,17 +41,7 @@ pub async fn handle_event(
4141 Event :: PeerDownloadCompleted { info_hash, peer } => {
4242 tracing:: debug!( info_hash = ?info_hash, peer = ?peer, "Peer download completed" , ) ;
4343
44- // Increment the number of downloads for the torrent
45- match db_torrent_repository. increase_number_of_downloads ( & info_hash) {
46- Ok ( ( ) ) => {
47- tracing:: debug!( info_hash = ?info_hash, "Number of downloads increased" ) ;
48- }
49- Err ( err) => {
50- tracing:: error!( info_hash = ?info_hash, error = ?err, "Failed to increase number of downloads" ) ;
51- }
52- }
53-
54- // Increment the number of downloads for all the torrents
44+ // Increment the number of downloads for all the torrents in memory
5545 let _unused = stats_repository
5646 . increment_counter (
5747 & metric_name ! ( TRACKER_CORE_PERSISTENT_TORRENTS_DOWNLOADS_TOTAL ) ,
@@ -60,9 +50,25 @@ pub async fn handle_event(
6050 )
6151 . await ;
6252
63- // todo:
64- // - Persist the metric into the database.
65- // - Load the metric from the database.
53+ // Increment the number of downloads for the torrent in the database
54+ match db_torrent_repository. increase_number_of_downloads ( & info_hash) {
55+ Ok ( ( ) ) => {
56+ tracing:: debug!( info_hash = ?info_hash, "Number of torrent downloads increased" ) ;
57+ }
58+ Err ( err) => {
59+ tracing:: error!( info_hash = ?info_hash, error = ?err, "Failed to increase number of downloads for the torrent" ) ;
60+ }
61+ }
62+
63+ // Increment the global number of downloads (for all torrents) in the database
64+ match db_torrent_repository. increase_global_number_of_downloads ( ) {
65+ Ok ( ( ) ) => {
66+ tracing:: debug!( "Global number of downloads increased" ) ;
67+ }
68+ Err ( err) => {
69+ tracing:: error!( error = ?err, "Failed to increase global number of downloads" ) ;
70+ }
71+ }
6672 }
6773 }
6874}
0 commit comments