Files
Marcos Paulo 59d5182799 feat(backlinks): wave 3
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-13 19:45:22 -03:00

34 lines
1.4 KiB
Rust

//! Performance of the unlinked-mention scan (run by hand: `cargo test
//! --release -p notescraft-backlinks -- --ignored`).
use std::collections::BTreeMap;
use std::time::Instant;
use notescraft_backlinks::{MAX_MENTIONS, unlinked_mentions};
use notescraft_index::Index;
#[test]
#[ignore = "perf: 20 000 notes, release mode, must scan in under 1 s"]
fn twenty_thousand_notes_scan_in_under_a_second() {
let mut index = Index::new();
let mut vault = BTreeMap::new();
index.update_note("Target.md", "the target note\n").unwrap();
vault.insert(String::from("Target.md"), String::from("the target note\n"));
for i in 0..20_000 {
let path = format!("notes/{i:05}.md");
let body = format!("talk about target number {i} in prose here\n#tag{i}\nsome more filler text\n");
index.update_note(&path, &body).unwrap();
vault.insert(path, body);
}
assert_eq!(index.len(), 20_001);
let start = Instant::now();
let report = unlinked_mentions(&index, &vault, "Target.md");
let elapsed = start.elapsed();
println!("20 000 notes: {:?}; {} mentions, {} skipped_large", elapsed, report.mentions.len(), report.skipped_large);
assert_eq!(report.mentions.len(), MAX_MENTIONS, "the cap of 10 000 results applies");
assert!(report.truncated);
assert_eq!(report.skipped_large, 0);
assert!(elapsed.as_secs_f64() < 1.0, "target is under 1 s, took {elapsed:?}");
}