From e732e7d61660931fa67859558c3d74ae5bb08f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Mon, 29 Apr 2024 13:46:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=BE=E5=AE=BD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=B1=A0=E7=9A=84=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=95=B0=E5=92=8C=E8=8E=B7=E5=8F=96=E6=97=B6=E9=97=B4,?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20time=20out=20=E9=94=99=E8=AF=AF=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/database.rs b/src/database.rs index b894273..543217a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,13 +1,18 @@ use anyhow::Result; use migration::{Migrator, MigratorTrait}; -use sea_orm::{Database, DatabaseConnection}; +use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use tokio::fs; use crate::config::CONFIG_DIR; pub async fn database_connection() -> Result { let target = CONFIG_DIR.join("data.sqlite"); fs::create_dir_all(&*CONFIG_DIR).await?; - Ok(Database::connect(format!("sqlite://{}?mode=rwc", target.to_str().unwrap())).await?) + let mut option = ConnectOptions::new(format!("sqlite://{}?mode=rwc", target.to_str().unwrap())); + option + .max_connections(100) + .min_connections(5) + .acquire_timeout(std::time::Duration::from_secs(90)); + Ok(Database::connect(option).await?) } pub async fn migrate_database(connection: &DatabaseConnection) -> Result<()> {