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 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 14:21:05 -04:00
co-authored by Claude Opus 5.5
parent dc9cf85cdc
commit 61658946d7
+10 -13
View File
@@ -452,15 +452,14 @@ pub fn get_note(conn: &Connection, id: &str) -> rusqlite::Result<Note> {
load_note(conn, id) 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<Vec<Note>> { pub fn reminders(conn: &Connection) -> rusqlite::Result<Vec<Note>> {
// The owner's reminders: a note shared with us neither alerts us nor is ours to let sql = format!("SELECT id FROM notes WHERE {OWN_REMINDERS} ORDER BY remind_at ASC");
// clear, the same as on the server. notes_where(conn, &sql, [])
notes_where(
conn,
"SELECT id FROM notes WHERE trashed = 0 AND remind_at IS NOT NULL AND permission = 'owner'
ORDER BY remind_at ASC",
[],
)
} }
/// Reminders due at or before `now_ms`, soonest first, trash excluded. /// Reminders due at or before `now_ms`, soonest first, trash excluded.
@@ -470,11 +469,9 @@ pub fn reminders(conn: &Connection) -> rusqlite::Result<Vec<Note>> {
/// parse is left out: it can never come due, and announcing it would be a guess. /// 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<Vec<DueReminder>> { pub fn due_reminders(conn: &Connection, now_ms: i64) -> rusqlite::Result<Vec<DueReminder>> {
let set: Vec<(String, String)> = { let set: Vec<(String, String)> = {
let mut stmt = conn.prepare( let mut stmt = conn.prepare(&format!(
"SELECT id, remind_at FROM notes "SELECT id, remind_at FROM notes WHERE {OWN_REMINDERS} ORDER BY remind_at ASC"
WHERE trashed = 0 AND remind_at IS NOT NULL AND permission = 'owner' ))?;
ORDER BY remind_at ASC",
)?;
let rows = stmt.query_map([], |r| Ok((r.get(0)?, r.get(1)?)))?; let rows = stmt.query_map([], |r| Ok((r.get(0)?, r.get(1)?)))?;
rows.collect::<rusqlite::Result<_>>()? rows.collect::<rusqlite::Result<_>>()?
}; };