From ee771e3734630be90493a0f86c08d9de27c7597c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 14:23:07 -0400 Subject: [PATCH] Every lock of the store goes through Db::conn Db::conn is documented as the one way to take the lock, yet five production and test sites reached past it with db.0.lock(): the startup summary, the desktop's trash sweep and config_get, and tests in sharing and update. All five now call conn(). DRY pass #2, batch 2, F8 (#5372). Co-Authored-By: Claude Opus 5.5 --- core/src/local/mod.rs | 2 +- core/src/sync/sharing.rs | 4 ++-- desktop/src-tauri/src/commands/local.rs | 2 +- desktop/src-tauri/src/lib.rs | 2 +- desktop/src-tauri/src/update.rs | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/local/mod.rs b/core/src/local/mod.rs index c2ab2a8..6db4203 100644 --- a/core/src/local/mod.rs +++ b/core/src/local/mod.rs @@ -84,7 +84,7 @@ pub fn open_in_memory() -> rusqlite::Result { /// A one-line count summary of the store, for the startup log. pub fn summary(db: &Db) -> String { - let conn = match db.0.lock() { + let conn = match db.conn() { Ok(c) => c, Err(_) => return "counts unavailable (lock poisoned)".to_string(), }; diff --git a/core/src/sync/sharing.rs b/core/src/sync/sharing.rs index 3ab1acd..61fa751 100644 --- a/core/src/sync/sharing.rs +++ b/core/src/sync/sharing.rs @@ -105,7 +105,7 @@ mod tests { fn the_shared_flag_follows_the_servers_answer_without_dirtying_the_note() { let db = db(); { - let conn = db.0.lock().unwrap(); + let conn = db.conn().unwrap(); conn.execute( "INSERT INTO notes (id, body, created_at, updated_at, dirty) VALUES ('n1', 'x', '2026-01-01', '2026-01-01', 0)", @@ -125,7 +125,7 @@ mod tests { created_at: None, }; let read = |db: &Db| -> (bool, i64) { - let conn = db.0.lock().unwrap(); + let conn = db.conn().unwrap(); conn.query_row("SELECT shared, dirty FROM notes WHERE id = 'n1'", [], |r| { Ok((r.get(0)?, r.get(1)?)) }) diff --git a/desktop/src-tauri/src/commands/local.rs b/desktop/src-tauri/src/commands/local.rs index 0b439ba..8abbff2 100644 --- a/desktop/src-tauri/src/commands/local.rs +++ b/desktop/src-tauri/src/commands/local.rs @@ -25,7 +25,7 @@ pub fn config_get(db: State<'_, Db>) -> PublicConfig { // be enforced. A store error falls back to the default rather than failing the // call — the app must still boot. let fallback = retention::LOCAL_RETENTION_DAYS; - let retention_days = match db.0.lock() { + let retention_days = match db.conn() { Ok(conn) => state::effective_retention_days(&conn, fallback).unwrap_or(fallback), Err(_) => fallback, }; diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index 5bfd698..6be1cc4 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -269,7 +269,7 @@ fn paint_window_before_the_webview_does(app: &tauri::App) { /// user is present for is one they can see the result of. A failure here is logged and /// stepped over — housekeeping must never be the reason the app won't open. fn sweep_local_trash(db: &local::Db) { - let conn = match db.0.lock() { + let conn = match db.conn() { Ok(conn) => conn, Err(_) => { log::warn!("skipping the trash sweep: store lock poisoned"); diff --git a/desktop/src-tauri/src/update.rs b/desktop/src-tauri/src/update.rs index 9274f08..efaf71b 100644 --- a/desktop/src-tauri/src/update.rs +++ b/desktop/src-tauri/src/update.rs @@ -553,7 +553,7 @@ mod tests { /// The channel `update_check` would actually use. fn effective(db: &Db) -> Channel { - let conn = db.0.lock().expect("lock"); + let conn = db.conn().expect("lock"); store::pref(&conn, CHANNEL_PREF) .expect("read pref") .as_deref() @@ -562,7 +562,7 @@ mod tests { } fn set_channel(db: &Db, channel: Channel) { - let conn = db.0.lock().expect("lock"); + let conn = db.conn().expect("lock"); store::set_pref(&conn, CHANNEL_PREF, channel.as_str()).expect("set pref"); } @@ -702,7 +702,7 @@ mod tests { } fn set_server(db: &Db, value: &str) { - let conn = db.0.lock().expect("lock"); + let conn = db.conn().expect("lock"); store::set_pref(&conn, SERVER_PREF, value).expect("set pref"); } @@ -780,7 +780,7 @@ mod tests { let db = db(); assert_eq!(token_for(&db, "https://notes.example.com"), Ok(None)); { - let conn = db.0.lock().expect("lock"); + let conn = db.conn().expect("lock"); state::set_link(&conn, "https://notes.example.com/", "tok").expect("link"); } assert_eq!(