Skip to content

Commit

Permalink
Profile updates on page view (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos R <[email protected]>
  • Loading branch information
CERLgit authored Feb 28, 2024
1 parent 6d3ada3 commit 6e7f9db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
tokio = { version = "1", features = ["full"] }
startgg = { path = "../startgg_api/" }
15 changes: 14 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -58,6 +62,15 @@ async fn view_player(
id: i32,
_limitguard: RocketGovernor<'_, RateLimitGuard>,
) -> Result<String, Error> {
//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
Expand Down

0 comments on commit 6e7f9db

Please sign in to comment.