Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Apple's own record stops being posted through the window
Yashwanth Kamireddi3c0ddd4fa21f
diff --git a/Cargo.lock b/Cargo.lockindex 8d2dd85..c401515 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3228,6 +3228,7 @@ dependencies = ["jiff","rusqlite","serde",+ "serde_json","tempfile","thiserror 2.0.20",]diff --git a/crates/quince-core/Cargo.toml b/crates/quince-core/Cargo.tomlindex 345d050..7203092 100644--- a/crates/quince-core/Cargo.toml+++ b/crates/quince-core/Cargo.toml@@ -12,4 +12,5 @@ serde.workspace = truethiserror = "2"[dev-dependencies]+serde_json.workspace = truetempfile = "3"diff --git a/crates/quince-core/src/reminders.rs b/crates/quince-core/src/reminders.rsindex ebfa14d..4e21c41 100644--- a/crates/quince-core/src/reminders.rs+++ b/crates/quince-core/src/reminders.rs@@ -40,7 +40,13 @@ pub struct Reminder {pub etag: Option<String>,/// Apple's original JSON for this reminder, kept verbatim so a write can echo every/// field back rather than only the ones we model.- #[serde(default, skip_serializing_if = "Option::is_none")]+ ///+ /// Never sent to the window. It averages five kilobytes a reminder on a real account,+ /// against about fourteen bytes of the title and notes anyone actually reads — so a list+ /// of seven hundred carried three and a half megabytes of it, and twenty thousand would+ /// have carried ninety. The interface has never looked at a byte of it: writes name a+ /// reminder by its guid and the record is read back from the library on this side.+ #[serde(default, skip_serializing)]pub raw: Option<String>,}@@ -931,3 +937,74 @@ mod count_tests {);}}++/// What a screenful of reminders weighs on its way to the window.+#[cfg(test)]+mod payload_tests {+ use super::*;++ /// Apple's record for one reminder runs to about five kilobytes. It is kept so a write can+ /// echo back every field this app does not model, and it is read on this side only — the+ /// interface names a reminder by its guid and has never looked at a byte of it.+ ///+ /// Sending it anyway made a list of seven hundred weigh three and a half megabytes.+ #[test]+ fn apples_own_record_never_leaves_this_side() {+ let apples_record = format!(r#"{{"fields":{{"padding":"{}"}}}}"#, "x".repeat(5_000));+ let reminder = Reminder {+ guid: "Reminder/1".into(),+ list_guid: "List/1".into(),+ title: "Buy milk".into(),+ notes: None,+ due_at: Some(1_789_000_000),+ completed_at: None,+ priority: 0,+ flagged: false,+ parent_guid: None,+ recur_frequency: None,+ recur_interval: None,+ etag: Some("e1".into()),+ raw: Some(apples_record),+ };++ let sent = serde_json::to_string(&reminder).unwrap();+ assert!(+ !sent.contains("padding"),+ "Apple's record must not cross into the window"+ );+ assert!(+ sent.len() < 400,+ "a reminder should weigh a few hundred bytes, not a few thousand: {}",+ sent.len()+ );+ assert!(sent.contains("Buy milk"), "what a person reads still goes");+ }++ /// A thousand reminders is an ordinary list on a busy account, and it has to stay small+ /// enough to cross a message channel without anyone noticing.+ #[test]+ fn a_thousand_reminders_stay_under_a_megabyte() {+ let many: Vec<Reminder> = (0..1_000)+ .map(|i| Reminder {+ guid: format!("Reminder/{i}"),+ list_guid: "List/1".into(),+ title: format!("Something to do number {i}"),+ notes: Some("with a note on it".into()),+ due_at: Some(1_789_000_000 + i),+ completed_at: None,+ priority: 0,+ flagged: false,+ parent_guid: None,+ recur_frequency: None,+ recur_interval: None,+ etag: Some(format!("e{i}")),+ raw: Some("y".repeat(5_000)),+ })+ .collect();+ let bytes = serde_json::to_vec(&many).unwrap().len();+ assert!(+ bytes < 1_048_576,+ "a thousand reminders came to {bytes} bytes"+ );+ }+}diff --git a/probe/examples/at_scale.rs b/probe/examples/at_scale.rsindex 4563301..5a557fd 100644--- a/probe/examples/at_scale.rs+++ b/probe/examples/at_scale.rs@@ -4,6 +4,16 @@ use quince_core::notes::{Note, NoteFolder};use quince_core::reminders::{Reminder, ReminderList};use std::time::Instant;+fn human(bytes: usize) -> String {+ if bytes < 1024 {+ format!("{bytes} B")+ } else if bytes < 1024 * 1024 {+ format!("{:.0} KB", bytes as f64 / 1024.0)+ } else {+ format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0))+ }+}+fn main() -> Result<(), Box<dyn std::error::Error>> {let dir = std::env::temp_dir().join(format!("quince-scale-{}", uuid::Uuid::new_v4()));std::fs::create_dir_all(&dir)?;@@ -113,47 +123,42 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {t.elapsed().as_millis());- println!("\n--- what the window asks for on every screen ---");- let t = Instant::now();- let n = lib.contacts(None)?.len();- println!(- "contacts(None) {n:>6} rows {:>7} ms",- t.elapsed().as_millis()- );-- let t = Instant::now();- let n = lib.contacts(Some("Surname7"))?.len();- println!(- "contacts(search) {n:>6} rows {:>7} ms",- t.elapsed().as_millis()- );+ println!("\n--- what each screen asks for, and what crosses into the window ---\n");- let t = Instant::now();- let n = lib.notes_in(None)?.len();- let bytes: usize = lib- .notes_in(None)?- .iter()- .map(|x| x.body.as_deref().unwrap_or("").len())- .sum();- println!(- "notes_in(None) {n:>6} rows {:>7} ms {} KB of bodies",- t.elapsed().as_millis(),- bytes / 1024- );+ macro_rules! weigh {+ ($label:expr, $call:expr) => {{+ let t = Instant::now();+ let rows = $call;+ let ms = t.elapsed().as_millis();+ let bytes = serde_json::to_vec(&rows).map(|v| v.len()).unwrap_or(0);+ println!(+ "{:<24} {:>6} rows {:>5} ms payload {:>9}",+ $label,+ rows.len(),+ ms,+ human(bytes)+ );+ bytes+ }};+ }- let t = Instant::now();- let n = lib.reminders_in("List/3", true)?.len();- println!(- "reminders_in(one list) {n:>6} rows {:>7} ms",- t.elapsed().as_millis()- );+ let mut worst = 0usize;+ worst = worst.max(weigh!("contacts(None)", lib.contacts(None)?));+ worst = worst.max(weigh!("contacts(search)", lib.contacts(Some("Surname7"))?));+ worst = worst.max(weigh!("notes_in(None)", lib.notes_in(None)?));+ worst = worst.max(weigh!("note_folders()", lib.note_folders()?));+ worst = worst.max(weigh!(+ "reminders_in(list)",+ lib.reminders_in("List/3", true)?+ ));+ worst = worst.max(weigh!(+ "reminders_due_between",+ lib.reminders_due_between(0, i64::MAX)?+ ));+ worst = worst.max(weigh!("reminder_lists()", lib.reminder_lists()?));+ worst = worst.max(weigh!("calendars()", lib.calendars()?));- let t = Instant::now();- let n = lib.reminders_due_between(0, i64::MAX)?.len();- println!(- "reminders_due_between {n:>6} rows {:>7} ms",- t.elapsed().as_millis()- );+ println!("\nlargest single payload: {}", human(worst));std::fs::remove_dir_all(&dir).ok();Ok(())