From c04d530a1a9e09dd26adc4116959e5481b970bc6 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 15 Jun 2025 18:26:07 +0200 Subject: feat(yt/update): Print a nice progress number This number obviously does not actually mean that we have finished updating (as it is incremented on staring). But it still provides some feedback, on how long the update will probably take. --- crates/yt/src/update/updater.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/yt/src/update/updater.rs b/crates/yt/src/update/updater.rs index 934b84b..21e30ed 100644 --- a/crates/yt/src/update/updater.rs +++ b/crates/yt/src/update/updater.rs @@ -35,6 +35,8 @@ pub(super) struct Updater { pool: LocalPoolHandle, } +static REACHED_NUMBER: AtomicUsize = const { AtomicUsize::new(1) }; + impl Updater { pub(super) fn new(max_backlog: usize, hashes: Vec) -> Self { // TODO(@bpeetz): The number should not be hardcoded. <2025-06-14> @@ -48,8 +50,10 @@ impl Updater { } pub(super) async fn update(self, app: &App, subscriptions: Vec) -> Result<()> { + let total_number = subscriptions.len(); + let mut stream = stream::iter(subscriptions) - .map(|sub| self.get_new_entries(sub)) + .map(|sub| self.get_new_entries(sub, total_number)) .buffer_unordered(16 * 4); while let Some(output) = stream.next().await { @@ -72,6 +76,7 @@ impl Updater { async fn get_new_entries( &self, sub: Subscription, + total_number: usize, ) -> Result> { let max_backlog = self.max_backlog; let hashes = self.hashes.clone(); @@ -96,7 +101,8 @@ impl Updater { clear_whole_line(); move_to_col(1); eprint!( - "Checking playlist {}...", + "({}/{total_number}) Checking playlist {}...", + REACHED_NUMBER.fetch_add(1, std::sync::atomic::Ordering::Relaxed), sub.name ); move_to_col(1); -- cgit 1.4.1