Skip to content

Commit

Permalink
utils: do not panic when index is stale...
Browse files Browse the repository at this point in the history
just go ahead and count the records "manually"...
  • Loading branch information
jqnatividad committed Jun 9, 2022
1 parent 6da1ecf commit 36dbd79
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,24 @@ pub fn show_env_vars() {
}
}

#[inline]
pub fn count_rows(conf: &Config) -> u64 {
conf.indexed().unwrap().map_or_else(
|| {
let indexed = conf.indexed().unwrap_or(None);

match indexed {
None => {
// index does not exist or is stale,
// count records manually
let mut rdr = conf.reader().unwrap();
let mut count = 0u64;
let mut record = csv::ByteRecord::new();
while rdr.read_byte_record(&mut record).unwrap() {
count += 1;
}
count
},
|idx| idx.count(),
)
}
Some(idx) => idx.count(),
}
}

#[cfg(any(feature = "full", feature = "lite"))]
Expand Down

0 comments on commit 36dbd79

Please sign in to comment.