perf: build entry excerpts in SQL, not in Rust

The list query selected every entry's full body so that excerpt() could
keep the first 180 characters of it. Listing a few years of diary moved
megabytes over the wire to render a sidebar, on every keystroke of an
incremental search.

It now reads the leading 1024 characters, which is more than an excerpt
can use, and infers truncation from the length of what came back.

Also pairs WAL with synchronous=NORMAL and an explicit busy_timeout — the
usual settings for it, and neither was being set.
This commit is contained in:
nvrl committed 2026-09-05 09:07:28 +02:00
1 parent 1e0f2f8792
commit f42c0c6e4b
2 files changed
+67 -16

No files matched your search

+8 -1
View File
@@ -9,7 +9,9 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use axum::Router;
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions};
use sqlx::sqlite::{
SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous,
};
use axum::http::{header, HeaderValue};
use tower_http::{
compression::CompressionLayer, set_header::SetResponseHeaderLayer, trace::TraceLayer,
@@ -47,6 +49,11 @@ async fn main() -> Result<()> {
.filename(config.data_dir.join("diary.db"))
.create_if_missing(true)
.journal_mode(SqliteJournalMode::Wal)
// The standard pairing for WAL: fsync at checkpoints rather
// than on every commit. A crash can cost the last transaction,
// never the database.
.synchronous(SqliteSynchronous::Normal)
.busy_timeout(std::time::Duration::from_secs(10))
.foreign_keys(true),
)
.await