LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
PERF-SMART: test that adding or removing an album forgets the reorder guard; fix comment wording and What's New figure
Nathaniel Ledford9673a69bec4e
diff --git a/crates/catalog/src/rules.rs b/crates/catalog/src/rules.rsindex d0ea85417..44d2fbe58 100644--- a/crates/catalog/src/rules.rs+++ b/crates/catalog/src/rules.rs@@ -1062,9 +1062,9 @@ const COST_ALBUM: u8 = 3;impl Rule {/// A rule's tier: 0 numbers, choices and yes/no questions about one photo's own record (and- /// anything that is false at once: an unknown field or a missing album); 1 dates, keyword and+ /// anything that is settled at once: an unknown field or a missing album); 1 dates, keyword and/// people lists, short single fields, an index lookup and a plain album's list (a folder holds no photos here: an empty lookup); 2 text built- /// from several fields and file paths (they copy and lower-case the text); 3 a smart album,+ /// from several fields and file paths (long strings, matched for each photo); 3 a smart album,/// which runs a whole rule set for the photo. A group costs as much as its dearest rule.fn cost(&self, cat: &Catalog) -> u8 {match self {@@ -1076,9 +1076,9 @@ impl Rule {Some(_) => COST_SMALL,}),"text" | "filePath" | "location" => COST_TEXT,- "keywords" | "person" | "personCount" | "stacked" | "sameContent" | "copyName" | "fileName" | "extension" | "format" | "title"- | "caption" | "altText" | "city" | "state" | "country" | "camera" | "lens" | "creator" | "copyright" | "captureDate"- | "importDate" | "editDate" | "shutterSpeed" | "aspect" => COST_SMALL,+ "keywords" | "person" | "personCount" | "stacked" | "copyName" | "fileName" | "extension" | "format" | "title" | "caption"+ | "altText" | "city" | "state" | "country" | "camera" | "lens" | "creator" | "copyright" | "captureDate" | "importDate"+ | "editDate" | "shutterSpeed" | "aspect" => COST_SMALL,_ => COST_SCALAR,},}diff --git a/crates/catalog/src/tests_rule_order.rs b/crates/catalog/src/tests_rule_order.rsindex 281e058be..d3f448674 100644--- a/crates/catalog/src/tests_rule_order.rs+++ b/crates/catalog/src/tests_rule_order.rs@@ -326,3 +326,40 @@ fn a_chain_as_deep_as_the_limit_keeps_the_written_order() {assert!(c.keeps_written_order());assert_eq!(ask(&c), as_written);}++/// What was worked out from the albums (whether rules may be tested cheapest first) is worked out+/// again after an album is added or removed: 31 smart albums in a chain are fine, a 32nd on top of+/// it reaches the depth limit (the written order from then on), and taking it away lifts that.+#[test]+fn adding_or_removing_an_album_forgets_whether_the_rules_may_be_reordered() {+ let mut c = Catalog::new();+ let mut p = Photo::new(c.alloc_photo_id(), Source::File { path: "/a/1.jpg".into() }, "1.jpg", "JPEG", 6000, 4000, "2026-09-30T10:00:00");+ p.flag = Flag::Pick;+ let photo = p.id;+ c.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();+ let album = |id: AlbumId| json!({"field": "album", "op": "is", "value": id.0});+ let smart = |c: &mut Catalog, name: &str, rules: serde_json::Value| {+ let id = c.alloc_album_id();+ c.apply(Op::AddAlbum { album: Album { smart: Some(Box::new(filter(rules))), ..Album::new(id, name) } }).unwrap();+ id+ };+ // S1 tests S2 … S30 tests S31, which tests nothing: 31 albums+ let mut chain = vec![smart(&mut c, "S31", json!({"match": "all", "rules": []}))];+ for i in (1..=30).rev() {+ let next = chain[chain.len() - 1];+ chain.push(smart(&mut c, &format!("S{i}"), json!({"match": "all", "rules": [album(next)]})));+ }+ let bottom = chain[0];+ let top = chain[30];+ let ask = |c: &Catalog| [top, bottom].map(|id| (c.album_contains(id, c.photo(photo).unwrap()), c.album_photos(id), c.album_count(id)));+ assert!(!c.keeps_written_order(), "31 albums in a chain are under the limit (worked out, and remembered)");+ let before = ask(&c);+ let head = smart(&mut c, "S0", json!({"match": "all", "rules": [album(top)]}));+ assert!(c.keeps_written_order(), "a 32nd album on top of the chain reaches the depth limit");+ assert_eq!(c.clone().keeps_written_order(), c.keeps_written_order(), "as a catalog that worked it out afresh");+ assert_eq!(ask(&c), ask(&c.clone()));+ c.apply(Op::RemoveAlbum { id: head }).unwrap();+ assert!(!c.keeps_written_order(), "without it the chain is under the limit again");+ assert_eq!(c.clone().keeps_written_order(), c.keeps_written_order());+ assert_eq!(ask(&c), before);+}diff --git a/docs/whats-new.md b/docs/whats-new.mdindex c24c4c516..a271c066d 100644--- a/docs/whats-new.md+++ b/docs/whats-new.md@@ -163,8 +163,8 @@other album is asked about them. The photos in the album and their order are the same, and the rules still show inthe order you wrote them. (A library whose smart albums test each other in a circle, which LightCraft doesn't letyou make, or test each other 32 deep, keeps testing the rules as written.) On a 312,000-photo test library, opening- one such album went from about 224 ms to about 100 ms, and opening 51 of them in turn from about 19 s to about- 5.8 s (a busy machine, so rough numbers).+ 51 such albums in turn went from about 19 s to about 5.8 s (about 377 ms to 113 ms each; a busy machine,+ so rough numbers).### Sharper resampling in HDR and panorama merges- Merged photos (HDR and panorama) are resampled with a sharper filter (Lanczos-3 instead of bilinear). Moving a