about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 18:29:58 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 11:45:16 +0200
commitc05f4317b299f1ebaff4955339f6d9ce44e9891b (patch)
tree7166333fb49aaafc04d5f80a5e500dc3e6d047f0
parentfeat(downloader): Display the sizes, when waiting for a cache size reduction (diff)
downloadyt-c05f4317b299f1ebaff4955339f6d9ce44e9891b.tar.gz
yt-c05f4317b299f1ebaff4955339f6d9ce44e9891b.zip
feat(status): Also show the cache usage
-rw-r--r--src/download/mod.rs2
-rw-r--r--src/status/mod.rs42
2 files changed, 26 insertions, 18 deletions
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<u64> {
+    pub async fn get_current_cache_allocation(app: &App) -> Result<u64> {
         fn dir_size(mut dir: fs::ReadDir) -> BoxFuture<'static, Result<u64>> {
             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 <https://www.gnu.org/licenses/gpl-3.0.txt>.
 
-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::<Vec<&Video>>()
+            .count()
     };
     (@changing $videos:expr, $status:ident) => {
         $videos
             .iter()
             .filter(|vid| vid.status == VideoStatus::$status && vid.status_change)
-            .collect::<Vec<&Video>>()
+            .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(())