From c31ba2750fa0625c4a0d0f6df1a64dbd02967e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Wed, 12 Jun 2019 23:02:43 +0200 Subject: [PATCH] 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. --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.rs b/src/main.rs index 09939ca..9f276da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,6 +119,13 @@ fn main() { .help("The maximum state group to process up to") .takes_value(true) .required(false), + ).arg( + Arg::with_name("min_saved_rows") + .short("m") + .value_name("COUNT") + .help("Suppress output if fewer than COUNT rows would be saved") + .takes_value(true) + .required(false), ).arg( Arg::with_name("output_file") .short("o") @@ -165,6 +172,10 @@ fn main() { .value_of("max_state_group") .map(|s| s.parse().expect("max_state_group must be an integer")); + let min_saved_rows = matches + .value_of("min_saved_rows") + .map(|v| v.parse().expect("COUNT must be an integer")); + let transactions = matches.is_present("transactions"); let level_sizes = value_t_or_exit!(matches, "level_sizes", LevelSizes); @@ -217,6 +228,17 @@ fn main() { compressor.stats.state_groups_changed ); + if let Some(min) = min_saved_rows { + let saving = (original_summed_size - compressed_summed_size) as i32; + if saving < min { + println!( + "Only {} rows would be saved by this compression. Skipping output.", + saving + ); + return; + } + } + // If we are given an output file, we output the changes as SQL. If the // `transactions` argument is set we wrap each change to a state group in a // transaction.