Remove Duplicates: compare only the part of the range with data

Given whole columns ("range":"D:D"), Remove Duplicates compared a
million blank rows and reported 1,048,573 removed duplicates; given the
whole sheet it ran for minutes, as it also did on a table resized to
the whole sheet. Rows and columns past the used range are blank, so
they are left out: the result is the same and the counts match the
data.
This commit is contained in:
nihilist-narwhal
2026-10-10 02:49:31 -05:00
parent 684567cc9a
commit 7fece30d49
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -580,6 +580,9 @@ fn remove_duplicates(s: &mut Session, p: &Json) -> Result<Json> {
let r = data_range(s, p)?;
let d = s.doc()?;
let sh = d.wb.active().ok_or(EngineError::NoDocument)?;
// Rows and columns past the data are blank: only the part with data is compared (whole
// columns compared a million blank rows and reported them as removed duplicates).
let r = sh.used_range().and_then(|u| r.intersection(&u)).unwrap_or(RangeRef::cell(r.start));
let header = bool_param(p, "header").unwrap_or_else(|| guess_header(&d.wb, sh, r));
let cols: Vec<u32> = p
.get("columns")
+4
View File
@@ -181,6 +181,10 @@ fn whole_sheet_selection_stays_within_the_data() {
s.execute("edit.fillUp", json!({})).unwrap();
assert_eq!(v(&s, "A1"), Value::Number(5.0));
assert!(s.execute("edit.fillDown", json!({"range": "A1:Z1000000"})).is_err(), "too large to fill");
s.execute("range.setValues", json!({"range": "D1", "values": [[1], [1], [2]]})).unwrap();
let r = s.execute("data.removeDuplicates", json!({"range": "D:D", "header": false})).unwrap();
assert_eq!((r["removed"].clone(), r["remaining"].clone()), (json!(1), json!(2)));
assert!(s.execute("data.removeDuplicates", json!({"range": "A1:XFD1048576", "header": false})).is_ok());
}
#[test]