enhance: allow to adjust concurrency number
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user