separate indexes

This commit is contained in:
yggverse 2025-08-02 13:59:54 +03:00
parent 746bc8bd58
commit 2e40f7366f

View file

@ -13,11 +13,7 @@ use librqbit::{
use peers::Peers; use peers::Peers;
use preload::Preload; use preload::Preload;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, time::Duration,
num::NonZero,
os::unix::ffi::OsStrExt,
path::PathBuf,
time::Duration,
}; };
use trackers::Trackers; use trackers::Trackers;
use url::Url; use url::Url;
@ -143,8 +139,15 @@ async fn main() -> Result<()> {
{ {
Ok(r) => match r { Ok(r) => match r {
Ok(AddTorrentResponse::Added(id, mt)) => { Ok(AddTorrentResponse::Added(id, mt)) => {
let mut images: HashMap<PathBuf, usize> = HashMap::with_capacity( let mut images: HashSet<PathBuf> = HashSet::with_capacity(
config.preload_max_filecount.unwrap_or_default(), config
.preload_max_filecount
.unwrap_or(config.index_capacity),
);
let mut only_files: HashSet<usize> = HashSet::with_capacity(
config
.preload_max_filecount
.unwrap_or(config.index_capacity),
); );
mt.wait_until_initialized().await?; mt.wait_until_initialized().await?;
let (name, files, is_private, length, bytes) = mt.with_metadata(|m| { let (name, files, is_private, length, bytes) = mt.with_metadata(|m| {
@ -176,7 +179,8 @@ async fn main() -> Result<()> {
} }
continue; 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(); let mi = m.info.info();
( (
@ -213,9 +217,7 @@ async fn main() -> Result<()> {
m.torrent_bytes.clone().into() m.torrent_bytes.clone().into()
) )
})?; })?;
session session.update_only_files(&mt, &only_files).await?;
.update_only_files(&mt, &images.values().cloned().collect())
.await?;
session.unpause(&mt).await?; session.unpause(&mt).await?;
mt.wait_until_completed().await?; mt.wait_until_completed().await?;
assert!( assert!(
@ -231,12 +233,10 @@ async fn main() -> Result<()> {
None None
} else { } else {
let mut b = Vec::with_capacity(images.len()); let mut b = Vec::with_capacity(images.len());
for path in images.keys() { for p in images {
b.push(Image { b.push(Image {
bytes: preload.bytes(path)?, bytes: preload.bytes(&p)?,
path: path path: p.to_string_lossy().to_string(),
.to_string_lossy()
.to_string(),
}) })
} }
Some(b) Some(b)