server: Only use a single connection with SQlite
Some checks failed
Rust / pre_job (push) Has been cancelled
Rust / cargo test (push) Has been cancelled
Rust / cargo clippy (push) Has been cancelled
Rust / cargo fmt (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

Several writer connections can lock the DB and cause other inserts to fail.

A single connection should be enough given the usual workloads
This commit is contained in:
Valentin Tolmer 2024-10-30 15:31:48 +01:00 committed by nitnelave
parent 35fe521cbe
commit 143eb70bee
2 changed files with 12 additions and 1 deletions

View file

@ -17,6 +17,12 @@ impl From<&str> for DatabaseUrl {
}
}
impl DatabaseUrl {
pub fn db_type(&self) -> &str {
self.0.scheme()
}
}
impl std::fmt::Debug for DatabaseUrl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0.password().is_some() {

View file

@ -82,9 +82,14 @@ async fn ensure_group_exists(handler: &SqlBackendHandler, group_name: &str) -> R
async fn setup_sql_tables(database_url: &DatabaseUrl) -> Result<DatabaseConnection> {
let sql_pool = {
let num_connections = if database_url.db_type() == "sqlite" {
1
} else {
5
};
let mut sql_opt = sea_orm::ConnectOptions::new(database_url.to_string());
sql_opt
.max_connections(5)
.max_connections(num_connections)
.sqlx_logging(true)
.sqlx_logging_level(log::LevelFilter::Debug);
Database::connect(sql_opt).await?