From c05f4317b299f1ebaff4955339f6d9ce44e9891b Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 23 Aug 2024 18:29:58 +0200 Subject: feat(status): Also show the cache usage --- src/download/mod.rs | 2 +- src/status/mod.rs | 42 +++++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/download/mod.rs b/src/download/mod.rs index 4aee136..ad807f6 100644 --- a/src/download/mod.rs +++ b/src/download/mod.rs @@ -134,7 +134,7 @@ impl Downloader { Ok(()) } - async fn get_current_cache_allocation(app: &App) -> Result { + pub async fn get_current_cache_allocation(app: &App) -> Result { fn dir_size(mut dir: fs::ReadDir) -> BoxFuture<'static, Result> { async move { let mut acc = 0; diff --git a/src/status/mod.rs b/src/status/mod.rs index 1b24279..662a391 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -8,13 +8,15 @@ // You should have received a copy of the License along with this program. // If not, see . -use anyhow::Result; +use anyhow::{Context, Result}; +use bytes::Bytes; use crate::{ app::App, + download::Downloader, storage::{ subscriptions::get_subscriptions, - video_database::{getters::get_videos, Video, VideoStatus}, + video_database::{getters::get_videos, VideoStatus}, }, }; @@ -23,13 +25,13 @@ macro_rules! get { $videos .iter() .filter(|vid| vid.status == VideoStatus::$status) - .collect::>() + .count() }; (@changing $videos:expr, $status:ident) => { $videos .iter() .filter(|vid| vid.status == VideoStatus::$status && vid.status_change) - .collect::>() + .count() }; } @@ -51,27 +53,32 @@ pub async fn show(app: &App) -> Result<()> { .await?; // lengths - let picked_videos_len = (get!(all_videos, Pick)).len(); + let picked_videos_len = get!(all_videos, Pick); - let watch_videos_len = (get!(all_videos, Watch)).len(); - let cached_videos_len = (get!(all_videos, Cached)).len(); - let watched_videos_len = (get!(all_videos, Watched)).len(); + let watch_videos_len = get!(all_videos, Watch); + let cached_videos_len = get!(all_videos, Cached); + let watched_videos_len = get!(all_videos, Watched); - let drop_videos_len = (get!(all_videos, Drop)).len(); - let dropped_videos_len = (get!(all_videos, Dropped)).len(); + let drop_videos_len = get!(all_videos, Drop); + let dropped_videos_len = get!(all_videos, Dropped); // changing - let picked_videos_changing = (get!(@changing all_videos, Pick)).len(); + let picked_videos_changing = get!(@changing all_videos, Pick); - let watch_videos_changing = (get!(@changing all_videos, Watch)).len(); - let cached_videos_changing = (get!(@changing all_videos, Cached)).len(); - let watched_videos_changing = (get!(@changing all_videos, Watched)).len(); + let watch_videos_changing = get!(@changing all_videos, Watch); + let cached_videos_changing = get!(@changing all_videos, Cached); + let watched_videos_changing = get!(@changing all_videos, Watched); - let drop_videos_changing = (get!(@changing all_videos, Drop)).len(); - let dropped_videos_changing = (get!(@changing all_videos, Dropped)).len(); + let drop_videos_changing = get!(@changing all_videos, Drop); + let dropped_videos_changing = get!(@changing all_videos, Dropped); let subscriptions = get_subscriptions(&app).await?; let subscriptions_len = subscriptions.0.len(); + + let cache_usage_raw = Downloader::get_current_cache_allocation(app) + .await + .context("Failed to get current cache allocation")?; + let cache_usage = Bytes::new(cache_usage_raw); println!( "\ Picked Videos: {picked_videos_len} ({picked_videos_changing} changing) @@ -84,7 +91,8 @@ Drop Videos: {drop_videos_len} ({drop_videos_changing} changing) Dropped Videos: {dropped_videos_len} ({dropped_videos_changing} changing) - Subscriptions: {subscriptions_len}" + Subscriptions: {subscriptions_len} + Cache usage: {cache_usage}" ); Ok(()) -- cgit 1.4.1