enhance: allow to adjust concurrency number

This commit is contained in:
mokurin000
2025-07-31 10:45:08 +08:00
parent cb92337dee
commit 3ab53b426d
2 changed files with 12 additions and 9 deletions

View File

@@ -49,12 +49,12 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
EARLY_QUIT.store(true, Ordering::Relaxed);
})?;
let cmd = <Cli as Parser>::parse();
let Cli { command } = <Cli as Parser>::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<dyn snafu::Error>> {
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<dyn snafu::Error>> {
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<dyn snafu::Error>> {
}
}
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<dyn snafu::Error>> {
Result::<_, Box<dyn snafu::Error>>::Ok(resp?)
})
.buffer_unordered(20)
.buffer_unordered(concurrency) // slower to avoid being banned
.filter_map(async |r| r.ok())
.collect::<Vec<_>>()
.await;