feat: B50 fetchall impl
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use bincode::Decode;
|
||||
use bincode::Encode;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
@@ -13,14 +15,20 @@ pub struct GetUserRatingApi {
|
||||
pub user_id: u32,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
impl From<u32> for GetUserRatingApi {
|
||||
fn from(user_id: u32) -> Self {
|
||||
Self { user_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GetUserRatingApiResp {
|
||||
pub user_id: u32,
|
||||
pub user_rating: UserRating,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UserRating {
|
||||
/// total rating, now it's 0
|
||||
@@ -36,7 +44,7 @@ pub struct UserRating {
|
||||
pub udemae: Udemae,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MusicRating {
|
||||
/// Maimai music id
|
||||
@@ -54,7 +62,7 @@ pub struct MusicRating {
|
||||
pub achievement: i32,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Udemae {
|
||||
pub max_lose_num: i64,
|
||||
|
||||
@@ -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