From 4366e4613128794ac7c44e059118f129126f724f Mon Sep 17 00:00:00 2001 From: strebdom Date: Thu, 19 Nov 2026 15:10:48 +0100 Subject: [PATCH] fix(engine): say which history an edit's memory check dropped, and list what it doesn't check (#2431) --- crates/engine/src/lib.rs | 14 +++++++++++--- crates/engine/src/undo_memory.rs | 24 +++++++++++++++++++++++- docs/user-guide/analysis.md | 16 +++++++++------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 50a5e3db53..9893de7459 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -2050,10 +2050,18 @@ impl Session { let over = self.undo.len().saturating_sub(UNDO_LIMIT); self.undo.drain(..over); } - // Freed: by the copy (none left), or because the history moved on. - _ => { + // Not taken by a copy, but the history changed while a background edit ran (another + // edit, Undo, trimming): the steps can't follow on from it. Rare, and not about making + // room, so said each time. + Some(_) => { + let template = "Undo history set aside for a background edit of {layer} is dropped ({count} Undo or Redo steps), as the Undo history changed while the edit ran."; + let args = [("count", count.to_string().into()), ("layer", name.to_string().into())]; + self.notify_text(notice_text::NoticeText::format(template, args), false); + } + // Freed by the edit's copy (the hook took them). + None => { if self.undo_memory.say_room() { - let template = "Memory is nearly full: older Undo steps are dropped to make room for edits ({count} before editing {layer}). An edit that still doesn't fit is refused."; + let template = "Memory is nearly full: Redo steps, then the oldest Undo steps, are dropped to make room for edits ({count} before editing {layer}). An edit that still doesn't fit is refused."; let args = [("count", count.to_string().into()), ("layer", name.to_string().into())]; self.notify_text(notice_text::NoticeText::format(template, args), false); } diff --git a/crates/engine/src/undo_memory.rs b/crates/engine/src/undo_memory.rs index e7c2d8f838..f4be7e365c 100644 --- a/crates/engine/src/undo_memory.rs +++ b/crates/engine/src/undo_memory.rs @@ -664,7 +664,8 @@ mod tests { let mark = session.notice_mark(); session.run("layer.addDataText", &json!({"fileName": "third.csv", "text": "a\n1\n"})).unwrap(); let notices = session.notices_since(mark); - assert!(notices.iter().any(|n| n.text.contains("(3 before editing calc)")), "{notices:?}"); + assert!(notices.iter().any(|n| n.text.contains("background edit of calc is dropped (3 Undo or Redo steps)")), "{notices:?}"); + assert!(!notices.iter().any(|n| n.text.contains("make room")), "{notices:?}"); assert_eq!(session.undo_depth(), 2, "only the two later steps"); } @@ -731,6 +732,27 @@ mod tests { assert!(!session.notices_since(mark).iter().any(|n| n.text.contains("make room"))); } + /// Undo and Redo copy no rows and aren't checked (they are registered as `.view()`, so they + /// don't count as edits): they run when even one copy of the active layer doesn't fit, as the + /// way back from an edit (#2431). + #[test] + fn undo_and_redo_run_when_an_edit_would_not_fit() { + let mut session = session(4096); + session.undo_memory.limit = 1 << 30; + session.undo_memory.memory = None; + for text in ["b", "c"] { + edit(&mut session, &text.repeat(4096)); + } + session.active_layer = Some(session.map().layer_by_name("rows").unwrap().id); + session.undo_memory.memory = Some(4); + assert!(session.run("edit.setValue", &json!({"layer": "rows", "row": 0, "field": "text", "value": "d"})).is_err()); + session.run("edit.undo", &json!({})).unwrap(); + assert_eq!(value(&session), &Value::Text("b".repeat(4096))); + session.run("edit.redo", &json!({})).unwrap(); + assert_eq!(value(&session), &Value::Text("c".repeat(4096))); + assert_eq!((session.undo_depth(), session.can_redo()), (2, false)); + } + #[test] fn paste_special_is_not_measured_by_the_active_layer() { let mut session = session(4096); diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index 9d9bc468b0..4a9f4b5812 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1582,15 +1582,17 @@ computer's memory. When it doesn't fit, Redo steps are set aside first (the edit anyway), then the oldest Undo steps. They are freed only once the edit starts copying; an edit that fails before that, or is cancelled before it starts copying, gives them back, unless the project was changed while it ran in the background. One that fails after it started copying has -used them, as a finished edit would have. A message says when steps are freed, the -first time in a project. An edit that wouldn't fit even with no Undo -history is refused before anything changes, and the message gives the size of the copy and what is -held. An edit the desktop runs in the background is checked when it starts; one that needs Undo +used them, as a finished edit would have. A message says when steps are freed to make room, the +first time in a project, and each time steps set aside for a background edit are freed because the +Undo history changed while it ran. Undo and Redo copy nothing and aren't checked. An edit that +wouldn't fit even with no Undo history is refused before anything changes, and the message gives +the size of the copy and what is held. An edit the desktop runs in the background is checked when it starts; one that needs Undo steps set aside while another such edit is still running is refused, to run again once that one has finished. Edits made by a -script, model, task or plugin aren't checked, nor is reloading or repairing a layer's data, and the -web app doesn't check, as it can't read the memory. Sizes are estimated, counting each text and part -as the block of memory it takes, so they come out above the bytes themselves. +script, model, task or plugin aren't checked, nor is Paste Special (it makes a layer of its own) or +reloading or repairing a layer's data. Nothing is checked where RustGIS can't read the computer's +memory: in the web app, and on a computer that doesn't report it. Sizes are estimated, counting +each text and part as the block of memory it takes, so they come out above the bytes themselves. So a computer with 16 GB reads rasters of up to about 500 million samples. A run that passes on one computer can be refused on a smaller one; the error names the limit there. Project Raster (`raster.project`) puts a raster