refactor: split userid read & fetch
This commit is contained in:
@@ -85,6 +85,11 @@ pub enum Commands {
|
|||||||
concurrency: usize,
|
concurrency: usize,
|
||||||
},
|
},
|
||||||
#[cfg(feature = "fetchall")]
|
#[cfg(feature = "fetchall")]
|
||||||
|
ScrapeAllB50 {
|
||||||
|
#[arg(short, long, default_value_t = 5)]
|
||||||
|
concurrency: usize,
|
||||||
|
},
|
||||||
|
#[cfg(feature = "fetchall")]
|
||||||
ListAllUserDump {},
|
ListAllUserDump {},
|
||||||
|
|
||||||
Logout {
|
Logout {
|
||||||
|
|||||||
@@ -232,10 +232,28 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
|
|
||||||
#[cfg(feature = "fetchall")]
|
#[cfg(feature = "fetchall")]
|
||||||
Commands::ListAllUser { concurrency } => {
|
Commands::ListAllUser { concurrency } => {
|
||||||
use sdgb_api::title::methods::GetUserPreviewApi;
|
|
||||||
|
|
||||||
use crate::{cache::PLAYERS, utils::helpers::cached_concurrent_fetch};
|
use crate::{cache::PLAYERS, utils::helpers::cached_concurrent_fetch};
|
||||||
cached_concurrent_fetch::<GetUserPreviewApi>(&client, concurrency, PLAYERS).await?;
|
use sdgb_api::title::methods::GetUserPreviewApi;
|
||||||
|
use std::io::BufRead as _;
|
||||||
|
|
||||||
|
let mut user_ids = Vec::new();
|
||||||
|
{
|
||||||
|
let mut stdin = std::io::stdin().lock();
|
||||||
|
let mut buf = String::new();
|
||||||
|
|
||||||
|
while stdin.read_line(&mut buf).is_ok_and(|size| size != 0) {
|
||||||
|
if buf.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let user_id: u32 = buf.trim().parse()?;
|
||||||
|
buf.clear();
|
||||||
|
user_ids.push(user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cached_concurrent_fetch::<GetUserPreviewApi>(user_ids, &client, concurrency, PLAYERS)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "fetchall")]
|
#[cfg(feature = "fetchall")]
|
||||||
Commands::ListAllUserDump {} => {
|
Commands::ListAllUserDump {} => {
|
||||||
@@ -244,6 +262,14 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
|||||||
dump_cache::<GetUserPreviewApiResp>("players.json", PLAYERS)?;
|
dump_cache::<GetUserPreviewApiResp>("players.json", PLAYERS)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "fetchall")]
|
||||||
|
Commands::ScrapeAllB50 { concurrency } => {
|
||||||
|
use crate::{
|
||||||
|
cache::PLAYERS,
|
||||||
|
utils::helpers::{cached_concurrent_fetch, read_cache},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Commands::Userdata { user_id } => {
|
Commands::Userdata { user_id } => {
|
||||||
let action = async |_| match Sdgb1_50::request::<_, GetUserDataApiResp>(
|
let action = async |_| match Sdgb1_50::request::<_, GetUserDataApiResp>(
|
||||||
&client,
|
&client,
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
use std::{fs::OpenOptions, io::BufWriter};
|
use std::{fs::OpenOptions, io::BufWriter};
|
||||||
use std::{
|
use std::{path::Path, sync::atomic::Ordering};
|
||||||
io::{self, BufRead},
|
|
||||||
path::Path,
|
|
||||||
sync::atomic::Ordering,
|
|
||||||
};
|
|
||||||
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use nyquest_preset::nyquest::AsyncClient;
|
use nyquest_preset::nyquest::AsyncClient;
|
||||||
@@ -70,6 +66,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cached_concurrent_fetch<A: APIExt>(
|
pub async fn cached_concurrent_fetch<A: APIExt>(
|
||||||
|
user_ids: impl Into<Vec<u32>>,
|
||||||
client: &AsyncClient,
|
client: &AsyncClient,
|
||||||
concurrency: usize,
|
concurrency: usize,
|
||||||
definition: TableDefinition<'_, u32, Vec<u8>>,
|
definition: TableDefinition<'_, u32, Vec<u8>>,
|
||||||
@@ -78,22 +75,7 @@ where
|
|||||||
A::Payload: From<u32>,
|
A::Payload: From<u32>,
|
||||||
A::Response: Encode + for<'a> BorrowDecode<'a, ()> + HasUid,
|
A::Response: Encode + for<'a> BorrowDecode<'a, ()> + HasUid,
|
||||||
{
|
{
|
||||||
let mut user_ids = Vec::new();
|
let user_ids = user_ids.into();
|
||||||
{
|
|
||||||
let mut stdin = io::stdin().lock();
|
|
||||||
let mut buf = String::new();
|
|
||||||
|
|
||||||
while stdin.read_line(&mut buf).is_ok_and(|size| size != 0) {
|
|
||||||
if buf.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let user_id: u32 = buf.trim().parse()?;
|
|
||||||
buf.clear();
|
|
||||||
user_ids.push(user_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let _ = cache::init_db();
|
let _ = cache::init_db();
|
||||||
let read = cache::read_txn()?;
|
let read = cache::read_txn()?;
|
||||||
let write = cache::write_txn()?;
|
let write = cache::write_txn()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user