diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-06-15 18:26:07 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-06-15 18:26:07 +0200 |
commit | c04d530a1a9e09dd26adc4116959e5481b970bc6 (patch) | |
tree | 8989953ebff9f4e10d53ed8d18c4417ba269ff53 | |
parent | feat(yt/update): Support grouped updates (diff) | |
download | yt-c04d530a1a9e09dd26adc4116959e5481b970bc6.zip |
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.
-rw-r--r-- | crates/yt/src/update/updater.rs | 10 |
1 files changed, 8 insertions, 2 deletions
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<Hash>) -> 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<Subscription>) -> 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<impl Iterator<Item = (Subscription, InfoJson)>> { 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); |