Skip to content

Commit ced2788

Browse files
committed
fix: [#1502] import torrents' download counters from DB
when the tracker starts. In the current implementation all torrents that have benn downloaded at least once have to be in memory initializting the counter. Otherwise, the global counter for downloads for all torrents only includes downloads for the torrents being currently tracker by the tracker.
1 parent 46c7eae commit ced2788

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/tracker-core/src/torrent/manager.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl TorrentsManager {
6060
}
6161
}
6262

63-
/// Loads torrents from the persistent database into the in-memory repository.
63+
/// Loads torrents from the database into the in-memory repository.
6464
///
6565
/// This function retrieves the list of persistent torrent entries (which
6666
/// include only the aggregate metrics, not the detailed peer lists) from
@@ -70,8 +70,7 @@ impl TorrentsManager {
7070
///
7171
/// Returns a `databases::error::Error` if unable to load the persistent
7272
/// torrent data.
73-
#[allow(dead_code)]
74-
pub(crate) fn load_torrents_from_database(&self) -> Result<(), databases::error::Error> {
73+
pub fn load_torrents_from_database(&self) -> Result<(), databases::error::Error> {
7574
let persistent_torrents = self.db_torrent_repository.load_all()?;
7675

7776
self.in_memory_torrent_repository.import_persistent(&persistent_torrents);

src/app.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub async fn start(config: &Configuration, app_container: &Arc<AppContainer>) ->
6161
async fn load_data_from_database(config: &Configuration, app_container: &Arc<AppContainer>) {
6262
load_peer_keys(config, app_container).await;
6363
load_whitelisted_torrents(config, app_container).await;
64+
load_torrents_from_database(config, app_container);
6465
}
6566

6667
async fn start_jobs(config: &Configuration, app_container: &Arc<AppContainer>) -> JobManager {
@@ -109,6 +110,16 @@ async fn load_whitelisted_torrents(config: &Configuration, app_container: &Arc<A
109110
}
110111
}
111112

113+
fn load_torrents_from_database(config: &Configuration, app_container: &Arc<AppContainer>) {
114+
if config.core.tracker_policy.persistent_torrent_completed_stat {
115+
app_container
116+
.tracker_core_container
117+
.torrents_manager
118+
.load_torrents_from_database()
119+
.expect("Could not load torrents from database.");
120+
}
121+
}
122+
112123
fn start_http_core_event_listener(config: &Configuration, app_container: &Arc<AppContainer>, job_manager: &mut JobManager) {
113124
let opt_handle = jobs::http_tracker_core::start_event_listener(config, app_container);
114125

0 commit comments

Comments
 (0)