Skip to content

Commit

Permalink
fix: stats caching was inadvertently deleting the stats cache even …
Browse files Browse the repository at this point in the history
…when not required

forcing unnecessary recomputes
  • Loading branch information
jqnatividad committed Jan 20, 2025
1 parent f8eb1d7 commit 96e6d28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
{
log::info!(
"{path_file_stem}.stats.csv already exists and is current. Skipping compute \
and using cached stats instead - {time_saved} secs saved...",
and using cached stats instead - {time_saved} milliseconds saved...",
);
compute_stats = false;
} else {
Expand Down Expand Up @@ -904,11 +904,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
}
}

// ensure create_cache is false if the user specified --cache-threshold 0
if args.flag_cache_threshold == 0 {
create_cache = false;
};

wtr.flush()?;

if let Some(pb) = stdin_tempfile_path {
Expand Down Expand Up @@ -950,8 +945,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
fs::copy(currstats_filename.clone(), stats_pathbuf.clone())?;
}

if args.flag_cache_threshold.is_negative() && args.flag_cache_threshold % 10 == -5 {
// if the cache threshold is a negative number ending in 5,
if args.flag_cache_threshold == 0
|| (args.flag_cache_threshold.is_negative() && args.flag_cache_threshold % 10 == -5)
{
// if the cache threshold zero or is a negative number ending in 5,
// delete both the index file and the stats cache file
if autoindex_set {
let index_file = path.with_extension("csv.idx");
Expand All @@ -961,10 +958,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
log::warn!("Could not remove index file: {}", index_file.display());
}
}
create_cache = false;
}

if !create_cache {
// remove the stats cache file
if fs::remove_file(stats_pathbuf.clone()).is_err() {
// fails silently if it can't remove the stats file
Expand All @@ -973,6 +967,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
stats_pathbuf.display()
);
}
create_cache = false;
}

if compute_stats && create_cache {
Expand All @@ -995,8 +990,13 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

// save the stats data to "<FILESTEM>.stats.csv.data.jsonl"
if write_stats_jsonl {
stats_pathbuf.set_extension("data.jsonl");
util::csv_to_jsonl(&currstats_filename, &get_stats_data_types(), &stats_pathbuf)?;
let mut stats_jsonl_pathbuf = stats_pathbuf.clone();
stats_jsonl_pathbuf.set_extension("data.jsonl");
util::csv_to_jsonl(
&currstats_filename,
&get_stats_data_types(),
&stats_jsonl_pathbuf,
)?;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ fn stats_with_date_inference_variance_stddev() {
.arg("--dates-whitelist")
.arg("aLL");

wrk.assert_success(&mut cmd);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);

wrk.create("in2.csv", got);
Expand Down

0 comments on commit 96e6d28

Please sign in to comment.