catalog: repair drops the derived lookups before it copies photos

`repair` copies every photo others hold (`Arc::make_mut`) without reporting a
change on a sound catalog, so the kept search and Text-rule texts stayed keyed
to the address a retained photo still has, and read that photo's old text after
it was edited on its own. Drop the lookups up front (they are built again when
asked), which also covers any copy a later change to `repair` adds.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nathaniel LedfordandClaude committed 2026-11-19 10:36:31 -05:00
1 parent 0c6f33d90f
commit 315cd357a9
3 files changed
+29 -4

No files matched your search

+2 -1
View File
@@ -134,7 +134,8 @@ impl std::hash::Hasher for IdHasher {
/// Where `p` is in memory. The contract of the kept texts: a text is used only for the photo at the
/// address it was made for. The catalog's own photos (`Arc<Photo>` contents) stay where they are
/// until `Arc::make_mut` copies one that others hold, which `photo_mut` reports ([`Indexes::text_moved`]);
/// until `Arc::make_mut` copies one that others hold, which `photo_mut` reports ([`Indexes::text_moved`]; `repair`
/// copies them in bulk and drops every lookup instead);
/// every op that changes a searched field makes the text again ([`Indexes::text_changed`]). A copy
/// of a photo (a candidate tried with other values) is at another address, so it is read from its
/// own fields, never from a text kept for the photo with its id. Only ids and addresses are
+6 -3
View File
@@ -1231,6 +1231,10 @@ impl Catalog {
/// wrote).
pub fn repair(&mut self) -> Vec<String> {
let mut changed = Vec::new();
// Photos others hold are copied below (`Arc::make_mut`), which moves them in memory and strands the text kept
// for their address ([`index::Indexes`]), and stacks and albums change outside `apply`: nothing derived is
// kept across a repair, and the lookups are built again when asked.
self.index = index::Indexes::default();
// Segmentation grids shared by the snapshot this was read from (issue #2154): each
// reference takes its grid's data, and the table is not kept — a live catalog always
// stores the data inline, so masks render and serialize without the snapshot's table.
@@ -1341,9 +1345,8 @@ impl Catalog {
self.next_stack = self.next_stack.max(stack);
}
if !changed.is_empty() {
// stacks and albums changed outside `apply`: the lookups are built again when asked
self.index = index::Indexes::default();
// (and what was worked out from the albums, the guard of [`Self::keeps_written_order`] too)
// stacks and albums changed outside `apply`: what was worked out from the albums is made again (the guard of
// [`Self::keeps_written_order`] too)
self.plans = PlansMemo::default();
}
changed
+21
View File
@@ -373,6 +373,27 @@ fn a_clone_builds_its_own() {
assert_current(&c);
}
/// `repair` copies the photos others hold (`Arc::make_mut`) without reporting a change, so the cache would
/// still keep a text for the address the retained photo has. The retained photo, changed on its own, is
/// read from its fields, never from the text kept for the photo with its id.
#[test]
fn repair_keeps_no_text_for_a_photo_it_copied() {
let mut c = library();
warm(&c);
let mut held = c.photo(PhotoId(1)).unwrap().clone();
assert!(c.repair().is_empty(), "a sound catalog");
assert!(!std::ptr::eq(&*held, &**c.photo(PhotoId(1)).unwrap()), "repair copied the photo");
std::sync::Arc::make_mut(&mut held).meta.title = "Trip to Nara".into();
let nara = Filter { text: "nara".into(), ..Default::default() };
let osaka = Filter { text: "ōsaka".into(), ..Default::default() };
assert!(nara.matches(&held, &c), "the retained photo's own title");
assert!(!osaka.matches(&held, &c), "not the title it had");
assert!(text_rule("contains", "nara").matches(&held, &c), "the Text rule reads the retained photo's own title");
assert!(!text_rule("contains", "ōsaka").matches(&held, &c));
warm(&c);
assert_eq!((found(&c, "ōsaka"), found(&c, "nara")), (1, 0));
}
/// The words of Text rules (not the search) read the same with the cache as without: what the fields give when each
/// photo is read alone (a copy of a photo is not the catalog's own, so the text kept for its id is not used), and what the
/// kept text gives.