Skip to content

Commit

Permalink
Merge pull request #86 from osu-tournament-rating/hotfix/truncate-pts
Browse files Browse the repository at this point in the history
  • Loading branch information
hburn7 authored Dec 26, 2024
2 parents a93be01 + 4da9741 commit 0302fae
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/database/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ impl DbClient {
}

pub async fn save_results(&self, player_ratings: &[PlayerRating]) {
self.truncate_rating_adjustments().await;
self.truncate_player_ratings().await;
self.truncate_table("rating_adjustments").await;
self.truncate_table("player_ratings").await;
self.truncate_table("player_tournament_stats").await;

self.save_ratings_and_adjustments_with_mapping(&player_ratings).await;

Expand Down Expand Up @@ -450,14 +451,6 @@ impl DbClient {
self.client.execute(query, values).await.unwrap();
}

async fn truncate_player_ratings(&self) {
self.client
.execute("TRUNCATE TABLE player_ratings RESTART IDENTITY CASCADE", &[])
.await
.unwrap();
println!("Truncated player_ratings table!");
}

pub async fn roll_forward_processing_statuses(&self, matches: &[Match]) {
println!("Updating processing status for all matches");

Expand Down Expand Up @@ -498,13 +491,16 @@ impl DbClient {
self.client.execute(tournament_update_sql.as_str(), &[]).await.unwrap();
}

async fn truncate_rating_adjustments(&self) {
async fn truncate_table(&self, table: &str) {
self.client
.execute("TRUNCATE TABLE rating_adjustments RESTART IDENTITY CASCADE", &[])
.execute(
format!("TRUNCATE TABLE {} RESTART IDENTITY CASCADE", table).as_str(),
&[]
)
.await
.unwrap();

println!("Truncated rating_adjustments table!");
println!("Truncated the {} table!", table);
}

// Access the underlying Client
Expand Down

0 comments on commit 0302fae

Please sign in to comment.