feat: B50 fetchall impl
This commit is contained in:
@@ -264,10 +264,22 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
||||
|
||||
#[cfg(feature = "fetchall")]
|
||||
Commands::ScrapeAllB50 { concurrency } => {
|
||||
use sdgb_api::title::methods;
|
||||
|
||||
use crate::{
|
||||
cache::PLAYERS,
|
||||
utils::helpers::{cached_concurrent_fetch, read_cache},
|
||||
cache::{PLAYER_B50, PLAYERS},
|
||||
utils::helpers::{cached_concurrent_fetch, read_cache_keys},
|
||||
};
|
||||
|
||||
let user_ids = read_cache_keys(PLAYERS)?;
|
||||
|
||||
cached_concurrent_fetch::<methods::GetUserRatingApi>(
|
||||
user_ids,
|
||||
&client,
|
||||
concurrency,
|
||||
PLAYER_B50,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Commands::Userdata { user_id } => {
|
||||
|
||||
@@ -20,6 +20,19 @@ use bincode::{BorrowDecode, Encode, borrow_decode_from_slice};
|
||||
|
||||
use crate::{EARLY_QUIT, cache};
|
||||
|
||||
pub fn read_cache_keys(
|
||||
definition: TableDefinition<'_, u32, Vec<u8>>,
|
||||
) -> Result<Vec<u32>, Box<dyn snafu::Error>> {
|
||||
let txn = cache::read_txn()?;
|
||||
let table = cache::open_table_ro(&txn, definition)?;
|
||||
|
||||
Ok(table
|
||||
.iter()?
|
||||
.flatten()
|
||||
.map(|(value, _)| value.value())
|
||||
.collect::<Vec<u32>>())
|
||||
}
|
||||
|
||||
pub fn read_cache<D>(
|
||||
definition: TableDefinition<'_, u32, Vec<u8>>,
|
||||
) -> Result<Vec<D>, Box<dyn snafu::Error>>
|
||||
@@ -123,7 +136,7 @@ where
|
||||
}
|
||||
Err(sdgb_api::ApiError::JSON { .. }) => {}
|
||||
Err(e) => {
|
||||
error!("preview failed: {e}");
|
||||
error!("fetch failed: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user