init
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/.idea
|
/.idea
|
||||||
*.db
|
*.db*
|
||||||
@@ -133,6 +133,9 @@ impl App {
|
|||||||
// (Note: join! supporte les handles déjà terminés ou annulés)
|
// (Note: join! supporte les handles déjà terminés ou annulés)
|
||||||
let _ = tokio::join!(http_handle, udp_handle);
|
let _ = tokio::join!(http_handle, udp_handle);
|
||||||
|
|
||||||
|
Database::checkpoint_wal(&self.state.db).await?;
|
||||||
|
Database::close(&self.state.db).await?;
|
||||||
|
|
||||||
tracing::info!("Closed the runtime application.");
|
tracing::info!("Closed the runtime application.");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use sea_orm::{ConnectOptions, Database as SeaDatabase, DatabaseConnection, DbErr};
|
use sea_orm::{
|
||||||
|
ConnectOptions, ConnectionTrait, Database as SeaDatabase, DatabaseConnection, DbBackend, DbErr,
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -15,8 +17,9 @@ impl Database {
|
|||||||
println!("{}", final_dsn);
|
println!("{}", final_dsn);
|
||||||
|
|
||||||
let mut opt = ConnectOptions::new(final_dsn);
|
let mut opt = ConnectOptions::new(final_dsn);
|
||||||
opt.max_connections(100)
|
let is_sqlite = dsn.starts_with("sqlite:");
|
||||||
.min_connections(5)
|
opt.max_connections(20)
|
||||||
|
.min_connections(2)
|
||||||
.connect_timeout(Duration::from_secs(8))
|
.connect_timeout(Duration::from_secs(8))
|
||||||
.acquire_timeout(Duration::from_secs(8))
|
.acquire_timeout(Duration::from_secs(8))
|
||||||
.sqlx_logging(true)
|
.sqlx_logging(true)
|
||||||
@@ -24,9 +27,34 @@ impl Database {
|
|||||||
|
|
||||||
let connection = SeaDatabase::connect(opt).await?;
|
let connection = SeaDatabase::connect(opt).await?;
|
||||||
|
|
||||||
|
if is_sqlite {
|
||||||
|
connection
|
||||||
|
.execute_unprepared("PRAGMA journal_mode = WAL")
|
||||||
|
.await?;
|
||||||
|
connection
|
||||||
|
.execute_unprepared("PRAGMA busy_timeout = 5000")
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Self { connection })
|
Ok(Self { connection })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn checkpoint_wal(connection: &DatabaseConnection) -> Result<(), DbErr> {
|
||||||
|
if connection.get_database_backend() != DbBackend::Sqlite {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
connection
|
||||||
|
.execute_unprepared("PRAGMA wal_checkpoint;")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn close(connection: &DatabaseConnection) -> Result<(), DbErr> {
|
||||||
|
connection.clone().close().await
|
||||||
|
}
|
||||||
|
|
||||||
// Tu peux ajouter ici tes méthodes helpers si tu veux encapsuler SeaORM
|
// Tu peux ajouter ici tes méthodes helpers si tu veux encapsuler SeaORM
|
||||||
// ex: pub async fn find_user(...)
|
// ex: pub async fn find_user(...)
|
||||||
pub fn get_connection(&self) -> &DatabaseConnection {
|
pub fn get_connection(&self) -> &DatabaseConnection {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use event_bus::Scope;
|
|||||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, Set};
|
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, Set};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Instant;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -88,6 +89,7 @@ impl MessageReactionService {
|
|||||||
emoji_id: Uuid,
|
emoji_id: Uuid,
|
||||||
skin_tone: Option<u8>,
|
skin_tone: Option<u8>,
|
||||||
) -> Result<(message_reaction::Model, bool), HTTPError> {
|
) -> Result<(message_reaction::Model, bool), HTTPError> {
|
||||||
|
let started_at = Instant::now();
|
||||||
let (message, _, skin_tone, server_id) =
|
let (message, _, skin_tone, server_id) =
|
||||||
self.validate(message_id, emoji_id, skin_tone).await?;
|
self.validate(message_id, emoji_id, skin_tone).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user