From 2e40f7366fbd1e267e185c538b204ba142095d7c Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 2 Aug 2025 13:59:54 +0300 Subject: [PATCH] separate indexes --- src/main.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40a88aa..e687ee1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,11 +13,7 @@ use librqbit::{ use peers::Peers; use preload::Preload; use std::{ - collections::{HashMap, HashSet}, - num::NonZero, - os::unix::ffi::OsStrExt, - path::PathBuf, - time::Duration, + collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, time::Duration, }; use trackers::Trackers; use url::Url; @@ -143,8 +139,15 @@ async fn main() -> Result<()> { { Ok(r) => match r { Ok(AddTorrentResponse::Added(id, mt)) => { - let mut images: HashMap = HashMap::with_capacity( - config.preload_max_filecount.unwrap_or_default(), + let mut images: HashSet = HashSet::with_capacity( + config + .preload_max_filecount + .unwrap_or(config.index_capacity), + ); + let mut only_files: HashSet = HashSet::with_capacity( + config + .preload_max_filecount + .unwrap_or(config.index_capacity), ); mt.wait_until_initialized().await?; let (name, files, is_private, length, bytes) = mt.with_metadata(|m| { @@ -176,7 +179,8 @@ async fn main() -> Result<()> { } continue; } - assert!(images.insert(info.relative_filename.clone(), id).is_none()) + assert!(images.insert(info.relative_filename.clone())); + assert!(only_files.insert(id)) } let mi = m.info.info(); ( @@ -213,9 +217,7 @@ async fn main() -> Result<()> { m.torrent_bytes.clone().into() ) })?; - session - .update_only_files(&mt, &images.values().cloned().collect()) - .await?; + session.update_only_files(&mt, &only_files).await?; session.unpause(&mt).await?; mt.wait_until_completed().await?; assert!( @@ -231,12 +233,10 @@ async fn main() -> Result<()> { None } else { let mut b = Vec::with_capacity(images.len()); - for path in images.keys() { + for p in images { b.push(Image { - bytes: preload.bytes(path)?, - path: path - .to_string_lossy() - .to_string(), + bytes: preload.bytes(&p)?, + path: p.to_string_lossy().to_string(), }) } Some(b)