From f43f876dfc7137530d5ff04045913545578cf89b Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 15 Nov 2026 11:36:28 -0500 Subject: [PATCH] fix(engine): count distinct link chart endpoints at capacity --- crates/engine/src/cmd/sharing.rs | 9 +++++++-- crates/engine/src/tests.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/sharing.rs b/crates/engine/src/cmd/sharing.rs index 417bd57a2a..d2b7dfd1f7 100644 --- a/crates/engine/src/cmd/sharing.rs +++ b/crates/engine/src/cmd/sharing.rs @@ -1418,13 +1418,18 @@ fn link_chart(s: &Session, rel: Option<&str>) -> Result<(String, Option) // out; one already in the chart may still be linked. // Up to 200 links drawn from it: destinations the chart has no room for don't count // toward them, so a later one it can draw still is. - let mut a = index.get(&(om, o.id, orow)).copied(); + let origin = (om, o.id, orow); + let mut a = index.get(&origin).copied(); + if a.is_none() && nodes.len() >= MAX_NODES { + continue; + } let mut drawn_here = 0; for &drow in drows { if drawn_here >= MAX_FEATURE_LINKS || links.len() >= MAX_LINKS { break; } - let new = usize::from(a.is_none()) + usize::from(!index.contains_key(&(dm, d.id, drow))); + let destination = (dm, d.id, drow); + let new = usize::from(a.is_none()) + usize::from(destination != origin && !index.contains_key(&destination)); if nodes.len() + new > MAX_NODES { continue; } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1441ebca4b..f037171a8f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12660,6 +12660,17 @@ fn a_link_chart_says_what_its_limits_leave_out() { let shows = "300 of the 301 related features and 20000 of the 20200 links"; assert_eq!(said(&s, mark, "Mesh"), [format!("Mesh: the link chart shows {shows}; {limits}")]); assert!(html.contains(&format!("Shows {shows}."))); + // A self-link needs one node, including the last available slot. Counting its endpoints + // twice would stop at 2,999 even though all 3,000 features and links fit. + let keys: Vec = (0..3000).map(|i| format!("self{i}")).collect(); + add(&mut s, "self.csv", &keys); + s.run("data.relate", &json!({"name": "Self", "origin": "self", "originKey": "key", "destination": "self", "destinationKey": "key"})) + .unwrap(); + let mark = s.notice_mark(); + s.run("share.linkChart", &json!({"relationship": "Self"})).unwrap(); + let (links, nodes, html) = drawn("Self"); + assert_eq!((links, nodes), (3000, 3000)); + assert!(said(&s, mark, "Self").is_empty() && !html.contains("Shows ")); let _ = std::fs::remove_dir_all(dir); }