diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/client.rs b/src/client.rs index 9281bce..9c1b29a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -14,7 +14,8 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use tokio::sync::Semaphore; pub struct GeClient { - counter: AtomicUsize, + download_counter: AtomicUsize, + cache_counter: AtomicUsize, client: Client, cache: Cache, par_limit: Semaphore, @@ -23,7 +24,8 @@ pub struct GeClient { impl GeClient { pub async fn new(par_limit: usize, cache: Cache) -> Result<Self> { Ok(Self { - counter: AtomicUsize::new(0), + download_counter: AtomicUsize::new(0), + cache_counter: AtomicUsize::new(0), par_limit: Semaphore::new(par_limit),cache, client: Client::builder().default_headers(HeaderMap::from_iter([ (HeaderName::from_static("user-agent"), HeaderValue::from_static("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36")), @@ -34,10 +36,11 @@ impl GeClient { pub async fn download(&self, path: &str) -> Result<Bytes> { let _permit = self.par_limit.acquire().await?; if let Some(d) = self.cache.get(path).await? { - debug!("cached {path:?}"); + let n = self.cache_counter.fetch_add(1, Ordering::Relaxed); + debug!("cached #{n} {path:?}"); Ok(d.into()) } else { - let n = self.counter.fetch_add(1, Ordering::Relaxed); + let n = self.download_counter.fetch_add(1, Ordering::Relaxed); info!("download #{n} {path:?}"); let res = self .client |