enhance: allow to adjust concurrency number
This commit is contained in:
@@ -41,7 +41,10 @@ pub enum Commands {
|
|||||||
user_id: u32,
|
user_id: u32,
|
||||||
},
|
},
|
||||||
|
|
||||||
ListAllUser,
|
ListAllUser {
|
||||||
|
#[arg(short, long, default_value_t = 5)]
|
||||||
|
concurrency: usize,
|
||||||
|
},
|
||||||
|
|
||||||
Logout {
|
Logout {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
EARLY_QUIT.store(true, Ordering::Relaxed);
|
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?;
|
let client = ClientBuilder::default().build_async().await?;
|
||||||
|
|
||||||
// TODO: refactor via enum_dispatch
|
// TODO: refactor via enum_dispatch
|
||||||
match cmd.command {
|
match command {
|
||||||
commands::Commands::Logout { user_id } => {
|
commands::Commands::Logout { user_id } => {
|
||||||
let logout: UserLogoutApiResp = Sdgb1_50::request(
|
let logout: UserLogoutApiResp = Sdgb1_50::request(
|
||||||
&client,
|
&client,
|
||||||
@@ -108,7 +108,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
println!("{}", String::from_utf8_lossy(&resp));
|
println!("{}", String::from_utf8_lossy(&resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
commands::Commands::ListAllUser => {
|
commands::Commands::ListAllUser { concurrency } => {
|
||||||
let mut stdin = io::stdin().lock();
|
let mut stdin = io::stdin().lock();
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let mut user_ids = Vec::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)
|
let players = futures_util::stream::iter(user_ids)
|
||||||
.map(async |user_id| {
|
.map(async |user_id| {
|
||||||
if EARLY_QUIT.load(Ordering::Relaxed) {
|
|
||||||
return Err("early skip due to ctrl-c")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "cache")]
|
#[cfg(feature = "cache")]
|
||||||
{
|
{
|
||||||
use redb::ReadableTable;
|
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>(
|
let resp = Sdgb1_50::request::<_, GetUserPreviewApiResp>(
|
||||||
&client,
|
&client,
|
||||||
APIMethod::GetUserPreviewApi,
|
APIMethod::GetUserPreviewApi,
|
||||||
@@ -187,7 +187,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
|
|
||||||
Result::<_, Box<dyn snafu::Error>>::Ok(resp?)
|
Result::<_, Box<dyn snafu::Error>>::Ok(resp?)
|
||||||
})
|
})
|
||||||
.buffer_unordered(20)
|
.buffer_unordered(concurrency) // slower to avoid being banned
|
||||||
.filter_map(async |r| r.ok())
|
.filter_map(async |r| r.ok())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
Reference in New Issue
Block a user