Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile updates on page view #115

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading