"Pending" has one definition: has_pending reads pending_fingerprint
has_pending listed the same four predicates as pending_fingerprint (dirty notes, dirty labels, pending deletes, unsent uploads) in a second query. It is now pending_fingerprint(..)?.is_some(). Counting where LIMIT 1 would do costs nothing on a local store. DRY pass #2, batch 2, F7 (#5372). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+5
-13
@@ -9,7 +9,7 @@
|
||||
//! patch (docs/sync.md). The server resolves conflicts last-write-wins by the client's
|
||||
//! `edited_at`, snapshotting anything it overwrites into the note's version history.
|
||||
|
||||
use rusqlite::{params, Connection, OptionalExtension};
|
||||
use rusqlite::{params, Connection};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::blobs::BlobStore;
|
||||
@@ -481,18 +481,10 @@ fn forget_pending_delete(conn: &Connection, change: &Change) -> rusqlite::Result
|
||||
|
||||
/// True when anything is waiting to go up. Cheap enough to call before a cycle.
|
||||
pub fn has_pending(conn: &Connection) -> rusqlite::Result<bool> {
|
||||
let pending: Option<i64> = conn
|
||||
.query_row(
|
||||
"SELECT 1 FROM notes WHERE dirty = 1
|
||||
UNION ALL SELECT 1 FROM labels WHERE dirty = 1
|
||||
UNION ALL SELECT 1 FROM pending_deletes
|
||||
UNION ALL SELECT 1 FROM attachments WHERE uploaded = 0 AND upload_error IS NULL
|
||||
LIMIT 1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
Ok(pending.is_some())
|
||||
// One definition of "pending": the fingerprint's. Counting where a LIMIT 1 would
|
||||
// do costs nothing on a local store, and two lists of the same four predicates
|
||||
// would drift.
|
||||
Ok(pending_fingerprint(conn)?.is_some())
|
||||
}
|
||||
|
||||
/// A value that changes whenever the set of pending changes does, and stays put
|
||||
|
||||
Reference in New Issue
Block a user