From 2f3dce43e95762c79999e1552d04af15d2996e9d Mon Sep 17 00:00:00 2001 From: Ryder Casazza Date: Tue, 21 Jul 2026 14:28:09 -0700 Subject: [PATCH] perf: keep torrent file count instead of the file list The per-file records were only ever used for a length sum and a files.len() > 1 check, so summing at construction and storing the count avoids carrying a Vec per torrent. Also drop the per-record String allocation in the Incomplete-tag check. --- src/releases.rs | 10 +++++----- src/scoring.rs | 2 +- src/service.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/releases.rs b/src/releases.rs index 16985fe..bba80fd 100644 --- a/src/releases.rs +++ b/src/releases.rs @@ -108,7 +108,7 @@ impl ReleasesClient { if !tracker.is_enabled(ab_passkey) { return None; } - if record.tags.contains(&"Incomplete".to_string()) { + if record.tags.iter().any(|tag| tag == "Incomplete") { return None; } let download_url = tracker.download_url(&record.url, ab_passkey)?; @@ -205,7 +205,7 @@ pub struct Torrent { pub source_url: String, pub info_hash: Option, pub published: Option, - pub files: Vec, + pub file_count: usize, pub size_bytes: u64, pub is_best: bool, pub dual_audio: bool, @@ -232,7 +232,7 @@ impl Torrent { .as_deref() .and_then(parse_timestamp) .or_else(|| record.created.as_deref().and_then(parse_timestamp)), - files: record.files, + file_count: record.files.len(), size_bytes, is_best: record.is_best, dual_audio: record.dual_audio, @@ -264,8 +264,8 @@ struct TorrentRecord { } #[derive(Debug, Clone, Deserialize)] -pub struct TorrentFile { - pub length: u64, +struct TorrentFile { + length: u64, } fn parse_timestamp(value: &str) -> Option { diff --git a/src/scoring.rs b/src/scoring.rs index 6e4f2b9..14bf379 100644 --- a/src/scoring.rs +++ b/src/scoring.rs @@ -176,7 +176,7 @@ mod tests { source_url: String::new(), info_hash: None, published: None, - files: Vec::new(), + file_count: 0, size_bytes: size, is_best: false, dual_audio: false, diff --git a/src/service.rs b/src/service.rs index c65bd97..3afe320 100644 --- a/src/service.rs +++ b/src/service.rs @@ -169,7 +169,7 @@ impl SearchService { let torrents: Vec = collected .into_iter() - .filter(|item| item.files.len() > 1) + .filter(|item| item.file_count > 1) .filter(|item| !self.is_excluded(item)) .collect(); let total = torrents.len(); @@ -391,7 +391,7 @@ impl SearchService { let include = match &media.format { MediaFormat::Movie => true, - format if self.format_allowed(format) => torrent.files.len() > 1, + format if self.format_allowed(format) => torrent.file_count > 1, _ => false, };