Skip to content

Commit e3a9609

Browse files
committed
perf: optimize SQLite with WAL mode and performance pragmas
1 parent cb16e13 commit e3a9609

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

backend/src/db/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ pub async fn create_pool(database_url: &str) -> Result<SqlitePool, sqlx::Error>
55
.max_connections(5)
66
.connect(database_url)
77
.await?;
8+
9+
sqlx::query("PRAGMA journal_mode = WAL")
10+
.execute(&pool)
11+
.await?;
12+
13+
sqlx::query("PRAGMA synchronous = NORMAL")
14+
.execute(&pool)
15+
.await?;
16+
17+
sqlx::query("PRAGMA cache_size = -64000")
18+
.execute(&pool)
19+
.await?;
20+
21+
sqlx::query("PRAGMA temp_store = MEMORY")
22+
.execute(&pool)
23+
.await?;
24+
825
Ok(pool)
926
}
1027

backend/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use handlers::{
2626
audit as audit_handlers, auth, budget, export, fixed_expenses, health, income, items, months,
2727
savings, stats,
2828
};
29+
use middleware::audit::audit_middleware;
2930
use middleware::auth::auth_middleware;
3031
use middleware::cache::{cache_middleware, CacheState};
3132
use middleware::ratelimit::{rate_limit_middleware, RateLimitState};
@@ -161,6 +162,10 @@ async fn main() {
161162
.fallback_service(ServeDir::new("/app/static"))
162163
.layer(cors)
163164
.with_state(pool.clone())
165+
.layer(axum::middleware::from_fn_with_state(
166+
pool.clone(),
167+
audit_middleware,
168+
))
164169
.route_layer(axum::middleware::from_fn_with_state(
165170
cache_state.clone(),
166171
cache_middleware,

0 commit comments

Comments
 (0)