Skip to content

Commit 357a77e

Browse files
committed
fix: load every symbol into the resolution cache
1 parent 12e823c commit 357a77e

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎src/indexing/pipeline/types.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,16 @@ impl SymbolLookupCache {
879879
/// For bulk indexing, prefer building the cache during INDEX stage.
880880
pub fn from_index(index: &crate::storage::DocumentIndex) -> PipelineResult<Self> {
881881
// Get total count to pre-allocate
882-
let count = index.document_count().unwrap_or(0) as usize;
882+
let count = index
883+
.count_symbols()
884+
.map_err(|e| PipelineError::Index(crate::IndexError::Storage(e)))?;
883885
let cache = Self::with_capacity(count);
886+
if count == 0 {
887+
return Ok(cache);
888+
}
884889

885-
// Load all symbols from Tantivy
886-
// Use a large limit to get all symbols
887890
let symbols = index
888-
.get_all_symbols(1_000_000)
891+
.get_all_symbols(count)
889892
.map_err(|e| PipelineError::Index(crate::IndexError::Storage(e)))?;
890893

891894
for symbol in symbols {

‎tests/cache_population.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use codanna::{
2+
FileId, Range, Symbol, SymbolId, SymbolKind, config::Settings,
3+
indexing::pipeline::types::SymbolLookupCache, storage::DocumentIndex,
4+
};
5+
6+
fn check_cache(count: u32) {
7+
let dir = tempfile::tempdir().unwrap();
8+
let index = DocumentIndex::new(dir.path(), &Settings::default()).unwrap();
9+
index.start_batch().unwrap();
10+
for id in 1..=count {
11+
let symbol = Symbol::new(
12+
SymbolId::new(id).unwrap(),
13+
"generated",
14+
SymbolKind::Function,
15+
FileId::new(1).unwrap(),
16+
Range::new(id, 0, id, 1),
17+
);
18+
index.add_document(&symbol, "generated.rs").unwrap();
19+
}
20+
index.commit_batch().unwrap();
21+
let cache = SymbolLookupCache::from_index(&index).unwrap();
22+
assert_eq!(cache.len(), count as usize);
23+
for id in 1..=count {
24+
assert!(cache.get_ref(SymbolId::new(id).unwrap()).is_some());
25+
}
26+
}
27+
28+
#[test]
29+
fn cache_contains_every_persisted_symbol() {
30+
check_cache(0);
31+
check_cache(7);
32+
}
33+
34+
#[test]
35+
#[ignore = "writes one million synthetic symbols; run explicitly for the former cache limit"]
36+
fn cache_exceeds_one_million_symbols() {
37+
check_cache(1_000_001);
38+
}

0 commit comments

Comments
 (0)