@@ -455,6 +455,7 @@ use std::time::Duration;
455
455
456
456
use bittorrent_primitives:: info_hash:: InfoHash ;
457
457
use torrent:: repository:: in_memory:: InMemoryTorrentRepository ;
458
+ use torrent:: repository:: persisted:: DatabasePersistentTorrentRepository ;
458
459
use torrust_tracker_clock:: clock:: Time ;
459
460
use torrust_tracker_configuration:: { AnnouncePolicy , Core , TORRENT_PEERS_LIMIT } ;
460
461
use torrust_tracker_primitives:: core:: { AnnounceData , ScrapeData } ;
@@ -487,6 +488,9 @@ pub struct Tracker {
487
488
488
489
/// The in-memory torrents repository.
489
490
torrents : Arc < InMemoryTorrentRepository > ,
491
+
492
+ /// The persistent torrents repository.
493
+ db_torrent_repository : Arc < DatabasePersistentTorrentRepository > ,
490
494
}
491
495
492
496
/// How many peers the peer announcing wants in the announce response.
@@ -547,6 +551,7 @@ impl Tracker {
547
551
database : database. clone ( ) ,
548
552
whitelist_authorization : whitelist_authorization. clone ( ) ,
549
553
torrents : Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ,
554
+ db_torrent_repository : Arc :: new ( DatabasePersistentTorrentRepository :: new ( database) ) ,
550
555
} )
551
556
}
552
557
@@ -665,7 +670,7 @@ impl Tracker {
665
670
///
666
671
/// Will return a `database::Error` if unable to load the list of `persistent_torrents` from the database.
667
672
pub fn load_torrents_from_database ( & self ) -> Result < ( ) , databases:: error:: Error > {
668
- let persistent_torrents = self . database . load_persistent_torrents ( ) ?;
673
+ let persistent_torrents = self . db_torrent_repository . load_all ( ) ?;
669
674
670
675
self . torrents . import_persistent ( & persistent_torrents) ;
671
676
@@ -723,7 +728,7 @@ impl Tracker {
723
728
let completed = swarm_metadata. downloaded ;
724
729
let info_hash = * info_hash;
725
730
726
- drop ( self . database . save_persistent_torrent ( & info_hash, completed) ) ;
731
+ drop ( self . db_torrent_repository . save ( & info_hash, completed) ) ;
727
732
}
728
733
}
729
734
@@ -759,7 +764,7 @@ impl Tracker {
759
764
///
760
765
/// Will return `Err` if unable to drop tables.
761
766
pub fn drop_database_tables ( & self ) -> Result < ( ) , databases:: error:: Error > {
762
- // todo: this is only used for testing. WE have to pass the database
767
+ // todo: this is only used for testing. We have to pass the database
763
768
// reference directly to the tests instead of via the tracker.
764
769
self . database . drop_database_tables ( )
765
770
}
0 commit comments