diff --git a/sdgb-api/src/title/model/get_user_rating_api/mod.rs b/sdgb-api/src/title/model/get_user_rating_api/mod.rs index acfbe8c..7d93b81 100644 --- a/sdgb-api/src/title/model/get_user_rating_api/mod.rs +++ b/sdgb-api/src/title/model/get_user_rating_api/mod.rs @@ -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 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, diff --git a/sdgb-cli/src/main.rs b/sdgb-cli/src/main.rs index 80143e5..ebf6be5 100644 --- a/sdgb-cli/src/main.rs +++ b/sdgb-cli/src/main.rs @@ -264,10 +264,22 @@ async fn main() -> Result<(), Box> { #[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::( + user_ids, + &client, + concurrency, + PLAYER_B50, + ) + .await?; } Commands::Userdata { user_id } => { diff --git a/sdgb-cli/src/utils/helpers/mod.rs b/sdgb-cli/src/utils/helpers/mod.rs index 138cd98..1485657 100644 --- a/sdgb-cli/src/utils/helpers/mod.rs +++ b/sdgb-cli/src/utils/helpers/mod.rs @@ -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>, +) -> Result, Box> { + let txn = cache::read_txn()?; + let table = cache::open_table_ro(&txn, definition)?; + + Ok(table + .iter()? + .flatten() + .map(|(value, _)| value.value()) + .collect::>()) +} + pub fn read_cache( definition: TableDefinition<'_, u32, Vec>, ) -> Result, Box> @@ -123,7 +136,7 @@ where } Err(sdgb_api::ApiError::JSON { .. }) => {} Err(e) => { - error!("preview failed: {e}"); + error!("fetch failed: {e}"); } }