diff --git a/Cargo.lock b/Cargo.lock index cfb737c..a9228ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2454,6 +2454,7 @@ dependencies = [ "rocket_cors", "serde_json", "smithe_lib", + "startgg", "thiserror", "tokio", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 69a3292..62617bd 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -12,4 +12,5 @@ serde_json = "1" thiserror = "1" smithe_lib = { path = "../lib" } rocket-governor = "0.2.0-rc.1" -tokio = { version = "1", features = ["full"] } \ No newline at end of file +tokio = { version = "1", features = ["full"] } +startgg = { path = "../startgg_api/" } diff --git a/backend/src/main.rs b/backend/src/main.rs index a5d9bd9..048b059 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -10,7 +10,7 @@ use rocket::{ use rocket_cors::{AllowedHeaders, AllowedOrigins}; use rocket_governor::{Quota, RocketGovernable, RocketGovernor}; use smithe_lib::{ - player::{get_all_like, get_player, get_top_two_characters}, + player::{add_new_player_to_pidgtm_db, get_all_like, get_player, get_top_two_characters}, set::{ get_competitor_type, get_head_to_head_record, get_set_losses_by_dq, get_set_losses_without_dqs, get_set_wins_by_dq, get_set_wins_without_dqs, @@ -20,6 +20,10 @@ use smithe_lib::{ }; use thiserror::Error; +use startgg::queries::player_getter::{make_pidgtm_player_getter_query, PIDGTM_PlayerGetterVars}; + +use std::sync::{Arc, Mutex}; + pub const DEV_ADDRESS: &str = "http://localhost:8080/"; pub const DEV_ADDRESS_2: &str = "http://127.0.0.1:8080/"; pub const PROD_ADDRESS: &str = "http://smithe.net"; @@ -58,6 +62,15 @@ async fn view_player( id: i32, _limitguard: RocketGovernor<'_, RateLimitGuard>, ) -> Result { + //Try to update if can but still serve old data otherwise + if let Ok(player_data) = + make_pidgtm_player_getter_query(id, Arc::new(Mutex::new(PIDGTM_PlayerGetterVars::empty()))) + .await + { + //Updates profile data or creates if not found + add_new_player_to_pidgtm_db(&player_data.player.unwrap()).await?; + } + // insert player page view smithe_lib::player_page_views::insert_player_page_view(id) .await