From d36064477234dba89a43e8cac8304c22e8b87794 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Jan 2026 22:24:47 +0400 Subject: [PATCH] fix: enable WAL mode and set busy timeout for SQLite --- src/core/db.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/db.rs b/src/core/db.rs index 080e586..ebf8d78 100644 --- a/src/core/db.rs +++ b/src/core/db.rs @@ -47,6 +47,16 @@ pub struct DatabaseStats { impl Database { pub fn new(path: &Path) -> Result { let conn = Connection::open(path)?; + + // Enable WAL mode for better concurrency and write performance + conn.pragma_update(None, "journal_mode", "WAL")?; + + // Set a busy timeout to handle lock contention gracefully (5 seconds) + conn.busy_timeout(std::time::Duration::from_secs(5))?; + + // Set synchronous mode to NORMAL for better performance while maintaining safety in WAL mode + conn.pragma_update(None, "synchronous", "NORMAL")?; + let db = Self { conn }; db.init_schema()?; Ok(db)