From 61658946d722ae4a98c4e84ca1c341ed502583a1 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 14:21:05 -0400 Subject: [PATCH] Which reminders are this device's is one predicate: OWN_REMINDERS reminders and due_reminders each wrote out "owner's, not trashed, has a time". The predicate is now one constant both queries read, carrying the reason a shared note's reminder is not ours. DRY pass #2, batch 2, F7 (#5372). Co-Authored-By: Claude Opus 5.5 --- core/src/local/store.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/src/local/store.rs b/core/src/local/store.rs index 2a7d175..060ae79 100644 --- a/core/src/local/store.rs +++ b/core/src/local/store.rs @@ -452,15 +452,14 @@ pub fn get_note(conn: &Connection, id: &str) -> rusqlite::Result { load_note(conn, id) } +/// Which notes' reminders are this device's to fire: the owner's, out of the trash. +/// A note shared with us neither alerts us nor is ours to clear, the same as on the +/// server. +const OWN_REMINDERS: &str = "trashed = 0 AND remind_at IS NOT NULL AND permission = 'owner'"; + pub fn reminders(conn: &Connection) -> rusqlite::Result> { - // The owner's reminders: a note shared with us neither alerts us nor is ours to - // clear, the same as on the server. - notes_where( - conn, - "SELECT id FROM notes WHERE trashed = 0 AND remind_at IS NOT NULL AND permission = 'owner' - ORDER BY remind_at ASC", - [], - ) + let sql = format!("SELECT id FROM notes WHERE {OWN_REMINDERS} ORDER BY remind_at ASC"); + notes_where(conn, &sql, []) } /// Reminders due at or before `now_ms`, soonest first, trash excluded. @@ -470,11 +469,9 @@ pub fn reminders(conn: &Connection) -> rusqlite::Result> { /// parse is left out: it can never come due, and announcing it would be a guess. pub fn due_reminders(conn: &Connection, now_ms: i64) -> rusqlite::Result> { let set: Vec<(String, String)> = { - let mut stmt = conn.prepare( - "SELECT id, remind_at FROM notes - WHERE trashed = 0 AND remind_at IS NOT NULL AND permission = 'owner' - ORDER BY remind_at ASC", - )?; + let mut stmt = conn.prepare(&format!( + "SELECT id, remind_at FROM notes WHERE {OWN_REMINDERS} ORDER BY remind_at ASC" + ))?; let rows = stmt.query_map([], |r| Ok((r.get(0)?, r.get(1)?)))?; rows.collect::>()? };