From 6530e20af2fa7cff39a10c0b10219c92863b5221 Mon Sep 17 00:00:00 2001 From: spinline Date: Sun, 8 Feb 2026 05:34:06 +0300 Subject: [PATCH] perf(db): enable SQLite WAL mode and performance settings - PRAGMA journal_mode=WAL - concurrent reads while writing - PRAGMA synchronous=NORMAL - faster than FULL, still safe - PRAGMA busy_timeout=5000 - reduces database locked errors Note: Existing databases should be deleted to enable WAL mode properly. --- backend/src/db.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/src/db.rs b/backend/src/db.rs index d22ea63..5190363 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -21,6 +21,21 @@ impl Db { } async fn run_migrations(&self) -> Result<()> { + // WAL mode - enables concurrent reads while writing + sqlx::query("PRAGMA journal_mode=WAL") + .execute(&self.pool) + .await?; + + // NORMAL synchronous - faster than FULL, still safe enough + sqlx::query("PRAGMA synchronous=NORMAL") + .execute(&self.pool) + .await?; + + // 5 second busy timeout - reduces "database locked" errors + sqlx::query("PRAGMA busy_timeout=5000") + .execute(&self.pool) + .await?; + sqlx::migrate!("./migrations").run(&self.pool).await?; Ok(()) }