Skip to content

Commit c31ba27

Browse files
jo-soheftig
authored andcommitted
main: new argument -m to give a minimal saving
Some compressions yield only a few hundred lines saving which isn't worth the database update and the time needed to validate the compression. With the new commandline argument `-m` the output would be suppressed, if not at least the given number of database records would be saved.
1 parent 88fc47d commit c31ba27

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ fn main() {
119119
.help("The maximum state group to process up to")
120120
.takes_value(true)
121121
.required(false),
122+
).arg(
123+
Arg::with_name("min_saved_rows")
124+
.short("m")
125+
.value_name("COUNT")
126+
.help("Suppress output if fewer than COUNT rows would be saved")
127+
.takes_value(true)
128+
.required(false),
122129
).arg(
123130
Arg::with_name("output_file")
124131
.short("o")
@@ -165,6 +172,10 @@ fn main() {
165172
.value_of("max_state_group")
166173
.map(|s| s.parse().expect("max_state_group must be an integer"));
167174

175+
let min_saved_rows = matches
176+
.value_of("min_saved_rows")
177+
.map(|v| v.parse().expect("COUNT must be an integer"));
178+
168179
let transactions = matches.is_present("transactions");
169180

170181
let level_sizes = value_t_or_exit!(matches, "level_sizes", LevelSizes);
@@ -217,6 +228,17 @@ fn main() {
217228
compressor.stats.state_groups_changed
218229
);
219230

231+
if let Some(min) = min_saved_rows {
232+
let saving = (original_summed_size - compressed_summed_size) as i32;
233+
if saving < min {
234+
println!(
235+
"Only {} rows would be saved by this compression. Skipping output.",
236+
saving
237+
);
238+
return;
239+
}
240+
}
241+
220242
// If we are given an output file, we output the changes as SQL. If the
221243
// `transactions` argument is set we wrap each change to a state group in a
222244
// transaction.

0 commit comments

Comments
 (0)