diff --git a/sdgb-cli/src/commands.rs b/sdgb-cli/src/commands.rs index fa3ccca..9c8a40f 100644 --- a/sdgb-cli/src/commands.rs +++ b/sdgb-cli/src/commands.rs @@ -41,7 +41,10 @@ pub enum Commands { user_id: u32, }, - ListAllUser, + ListAllUser { + #[arg(short, long, default_value_t = 5)] + concurrency: usize, + }, Logout { #[arg(short, long)] diff --git a/sdgb-cli/src/main.rs b/sdgb-cli/src/main.rs index 8e7d401..1727ad6 100644 --- a/sdgb-cli/src/main.rs +++ b/sdgb-cli/src/main.rs @@ -49,12 +49,12 @@ async fn main() -> Result<(), Box> { EARLY_QUIT.store(true, Ordering::Relaxed); })?; - let cmd = ::parse(); + let Cli { command } = ::parse(); let client = ClientBuilder::default().build_async().await?; // TODO: refactor via enum_dispatch - match cmd.command { + match command { commands::Commands::Logout { user_id } => { let logout: UserLogoutApiResp = Sdgb1_50::request( &client, @@ -108,7 +108,7 @@ async fn main() -> Result<(), Box> { println!("{}", String::from_utf8_lossy(&resp)); } - commands::Commands::ListAllUser => { + commands::Commands::ListAllUser { concurrency } => { let mut stdin = io::stdin().lock(); let mut buf = String::new(); let mut user_ids = Vec::new(); @@ -135,10 +135,6 @@ async fn main() -> Result<(), Box> { let players = futures_util::stream::iter(user_ids) .map(async |user_id| { - if EARLY_QUIT.load(Ordering::Relaxed) { - return Err("early skip due to ctrl-c")?; - } - #[cfg(feature = "cache")] { use redb::ReadableTable; @@ -154,6 +150,10 @@ async fn main() -> Result<(), Box> { } } + if EARLY_QUIT.load(Ordering::Relaxed) { + return Err("early skip due to ctrl-c")?; + } + let resp = Sdgb1_50::request::<_, GetUserPreviewApiResp>( &client, APIMethod::GetUserPreviewApi, @@ -187,7 +187,7 @@ async fn main() -> Result<(), Box> { Result::<_, Box>::Ok(resp?) }) - .buffer_unordered(20) + .buffer_unordered(concurrency) // slower to avoid being banned .filter_map(async |r| r.ok()) .collect::>() .await;