Remove servers from database that have opted out, create 50 postgres connections on startup

This commit is contained in:
funtimes909 committed 2025-04-20 12:49:54 +12:00
1 parent 6129898942
commit 3b9be2f2aa
2 files changed
+18 -2

No files matched your search

+17 -2
View File
@@ -1,12 +1,20 @@
use crate::colors::{RED, RESET};
use crate::response::Server;
use futures_core::stream::BoxStream;
use sqlx::postgres::PgRow;
use sqlx::postgres::{PgConnectOptions, PgQueryResult, PgRow};
use sqlx::{Error, PgPool, Pool, Postgres, Row};
use std::time::{SystemTime, UNIX_EPOCH};
pub async fn connect(url: &str) -> Pool<Postgres> {
match PgPool::connect(url).await {
let options = PgConnectOptions::new()
.host(url)
.application_name("ServerSeekerV2-Rust");
match sqlx::postgres::PgPoolOptions::new()
.max_connections(50)
.connect_with(options)
.await
{
Ok(pool) => pool,
Err(e) => panic!("{RED}Unable to connect to database: {e}{RESET}"),
}
@@ -108,3 +116,10 @@ pub async fn update(server: Server, conn: &PgPool, host: &(String, u16)) -> anyh
.await
.map_err(|_| anyhow::Error::msg("Failed to commit transaction!"))
}
pub async fn remove_server(address: String, conn: &PgPool) -> Result<PgQueryResult, Error> {
sqlx::query("DELETE FROM servers WHERE address = $1")
.bind(address)
.execute(conn)
.await
}
+1
View File
@@ -145,6 +145,7 @@ async fn run(host: (String, u16), state: Arc<State>) -> Result<(), RunError> {
let response = response::parse_response(results)?;
if response.check_opt_out() {
database::remove_server(host.0, &state.pool).await?;
return Err(RunError::ServerOptOut());
}