From 22199c55e6c6c9648d339e13e580a91e42887dd6 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 13 Aug 2025 16:04:16 +0300 Subject: [PATCH] use local timestamp for the ban timeout value --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 41902e1..687fbf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod config; mod preload; use anyhow::Result; -use chrono::{DateTime, Utc}; +use chrono::DateTime; use config::Config; use librqbit::{ AddTorrent, AddTorrentOptions, AddTorrentResponse, ConnectionOptions, PeerConnectionOptions, @@ -64,14 +64,14 @@ async fn main() -> Result<()> { }, ) .await?; - let mut ban: HashMap> = + let mut ban: HashMap> = HashMap::with_capacity(config.index_capacity); log::info!("crawler started at {time_init}"); loop { let time_queue = Local::now(); log::debug!("queue crawl begin at {time_queue}..."); ban.retain(|k, &mut v| { - let is_expired = v > Utc::now() - Duration::from_secs(config.ban); + let is_expired = v > time_queue - Duration::from_secs(config.ban); if is_expired { log::debug!( "remove `{}` from the ban list by timeout expire ({v})", @@ -201,7 +201,7 @@ async fn main() -> Result<()> { log::debug!( "skip awaiting the completion of preload `{h}` data (`{e}`)" ); - ban.insert(i, Utc::now()); + ban.insert(i, Local::now()); session .delete(librqbit::api::TorrentIdOrHash::Id(id), false) .await?; // * do not collect billions of slow torrents in the session pool @@ -223,14 +223,14 @@ async fn main() -> Result<()> { Ok(_) => panic!(), Err(e) => { log::debug!("failed to resolve torrent `{h}`: `{e}`."); - assert!(ban.insert(i, Utc::now()).is_none()); + assert!(ban.insert(i, Local::now()).is_none()); } }, Err(e) => { log::debug!( "skip awaiting the completion of adding torrent `{h}` data (`{e}`)" ); - assert!(ban.insert(i, Utc::now()).is_none()); + assert!(ban.insert(i, Local::now()).is_none()); } } }