server: Only use a single connection with SQlite
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:
committed by
nitnelave
parent
35fe521cbe
commit
143eb70bee
@@ -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 {
|
impl std::fmt::Debug for DatabaseUrl {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
if self.0.password().is_some() {
|
if self.0.password().is_some() {
|
||||||
|
|||||||
@@ -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> {
|
async fn setup_sql_tables(database_url: &DatabaseUrl) -> Result<DatabaseConnection> {
|
||||||
let sql_pool = {
|
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());
|
let mut sql_opt = sea_orm::ConnectOptions::new(database_url.to_string());
|
||||||
sql_opt
|
sql_opt
|
||||||
.max_connections(5)
|
.max_connections(num_connections)
|
||||||
.sqlx_logging(true)
|
.sqlx_logging(true)
|
||||||
.sqlx_logging_level(log::LevelFilter::Debug);
|
.sqlx_logging_level(log::LevelFilter::Debug);
|
||||||
Database::connect(sql_opt).await?
|
Database::connect(sql_opt).await?
|
||||||
|
|||||||
Reference in New Issue
Block a user