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

Truncate player_tournament_stats table and cleanup truncate functions #86

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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
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