mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 07:28:04 +08:00
feat: 放宽数据库连接池的连接数和获取时间,避免 time out 错误 (#87)
This commit is contained in:
+7
-2
@@ -1,13 +1,18 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use migration::{Migrator, MigratorTrait};
|
use migration::{Migrator, MigratorTrait};
|
||||||
use sea_orm::{Database, DatabaseConnection};
|
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use crate::config::CONFIG_DIR;
|
use crate::config::CONFIG_DIR;
|
||||||
pub async fn database_connection() -> Result<DatabaseConnection> {
|
pub async fn database_connection() -> Result<DatabaseConnection> {
|
||||||
let target = CONFIG_DIR.join("data.sqlite");
|
let target = CONFIG_DIR.join("data.sqlite");
|
||||||
fs::create_dir_all(&*CONFIG_DIR).await?;
|
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<()> {
|
pub async fn migrate_database(connection: &DatabaseConnection) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user