1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-10-16 09:37:27 +00:00

Tweak debug logging for bundle load and fetch

This commit is contained in:
Steffo 2023-03-24 13:01:52 +01:00
parent f9994c516a
commit 34c396b5de
Signed by: steffo
GPG key ID: 2A24051445686895
2 changed files with 18 additions and 11 deletions

View file

@ -28,6 +28,8 @@ pub struct CoreBundle {
impl CoreBundle {
/// Load a Core Bundle directory to create a [CoreBundle] instance.
pub fn load(bundle_path: &Path) -> LoadingResult<Self> {
log::debug!("Loading CoreBundle from: {}", bundle_path.as_os_str().to_string_lossy());
let metadata = BundleMetadata::load(&bundle_path.join("metadata.json"))?;
let locale = metadata.locale().ok_or(LoadingError::GettingLocale)?;
@ -46,8 +48,12 @@ impl CoreBundle {
/// Fetch from `base_url` the Core Bundle data with the given `locale`.
pub async fn fetch(client: &reqwest::Client, base_url: &str, locale: &str) -> LoadingResult<Self> {
let url = format!("{}/core/{}/data/globals-{}.json", base_url, locale, locale);
log::debug!("Fetching CoreBundle from {} ...", &url);
let globals = client
.get(format!("{base_url}/core/{locale}/data/globals-{locale}.json"))
.get(url)
.send()
.await
.map_err(LoadingError::RemoteFetching)?
@ -55,6 +61,8 @@ impl CoreBundle {
.await
.map_err(LoadingError::RemoteDeserializing)?;
log::debug!("Fetched CoreBundle: it defines {} regions, {} keywords, {} rarities, {} sets, {} spell speeds, and {} vocab terms!", &globals.regions.len(), &globals.keywords.len(), &globals.rarities.len(), &globals.sets.len(), &globals.spell_speeds.len(), &globals.vocab_terms.len());
Ok(Self {globals})
}
}
@ -83,13 +91,9 @@ pub fn create_globalindexes_from_wd() -> globals::LocalizedGlobalsIndexes {
pub async fn create_globalindexes_from_dd_latest(locale: &str) -> globals::LocalizedGlobalsIndexes {
let client = reqwest::Client::new();
log::debug!("Fetching {} CoreBundle from Data Dragon...", locale);
let core = CoreBundle::fetch(&client, "https://dd.b.pvp.net/latest", locale).await
.expect("to be able to fetch CoreBundle");
log::debug!("Fetched {} CoreBundle: it defines {} regions, {} keywords, {} rarities, {} sets, {} spell speeds, and {} vocab terms!", locale, &core.globals.regions.len(), &core.globals.keywords.len(), &core.globals.rarities.len(), &core.globals.sets.len(), &core.globals.spell_speeds.len(), &core.globals.vocab_terms.len());
globals::LocalizedGlobalsIndexes::from(core.globals)
}

View file

@ -33,8 +33,9 @@ pub struct SetBundle {
impl SetBundle {
/// Load a Set Bundle directory to create a [SetBundle] instance.
pub fn load(bundle_path: &Path) -> LoadingResult<Self> {
let metadata = BundleMetadata::load(&bundle_path.join("metadata.json"))?;
log::debug!("Loading SetBundle from: {}", bundle_path.as_os_str().to_string_lossy());
let metadata = BundleMetadata::load(&bundle_path.join("metadata.json"))?;
let locale = metadata.locale().ok_or(LoadingError::GettingLocale)?;
let name = bundle_path
@ -60,8 +61,12 @@ impl SetBundle {
/// Fetch from `base_url` the Set Bundle data of the given `set` with the given `locale`.
pub async fn fetch(client: &reqwest::Client, base_url: &str, locale: &str, set: &str) -> LoadingResult<Self> {
let url = format!("{}/{}/{}/data/{}-{}.json", base_url, set, locale, set, locale);
log::debug!("Fetching SetBundle from {} ...", url);
let cards = client
.get(format!("{base_url}/{set}/{locale}/data/{set}-{locale}.json"))
.get(url)
.send()
.await
.map_err(LoadingError::RemoteFetching)?
@ -69,6 +74,8 @@ impl SetBundle {
.await
.map_err(LoadingError::RemoteDeserializing)?;
log::debug!("Fetched SetBundle: it defines {} cards!", cards.len());
Ok(Self {cards})
}
}
@ -153,13 +160,9 @@ pub async fn create_cardindex_from_dd_latest(locale: &str, known_set_codes: &Vec
let mut index = card::CardIndex::new();
for set_code in known_set_codes {
log::debug!("Fetching {} SetBundle with code {} from Data Dragon...", locale, &set_code);
let set = SetBundle::fetch(&client, "https://dd.b.pvp.net/latest", locale, &set_code).await
.expect("to be able to fetch set bundle");
log::debug!("Fetched {} SetBundle with code {}: it defines {} cards!", locale, &set_code, set.cards.len());
for card in set.cards {
index.insert(card.code.clone(), card);
}