diff options
-rw-r--r-- | src/tool.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tool.rs b/src/tool.rs index c431c09..abb12fa 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -9,6 +9,10 @@ pub fn tool_main(config: Config, action: &str, args: Vec<String>) -> Result<()> let newhost = args.get(1).ok_or(anyhow!("3rd arg is new host"))?; move_host(config, oldhost, newhost)?; } + "clear_host" => { + let host = args.get(0).ok_or(anyhow!("2nd arg is host to clear"))?; + clear_host(config, host)?; + } _ => bail!("unknown action"), } Ok(()) @@ -49,3 +53,27 @@ pub fn move_host(config: Config, oldhost: &str, newhost: &str) -> Result<()> { Ok(()) } + +pub fn clear_host(config: Config, host: &str) -> Result<()> { + let db = Database::open(config.database_path)?; + + let txn = db.begin_write()?; + { + let mut t_impressions = txn.open_table(T_IMPRESSIONS_RAW)?; + let mut t_weighted = txn.open_table(T_IMPRESSIONS_WEIGHTED)?; + + let imp = t_impressions + .remove(host)? + .map(|g| g.value()) + .unwrap_or_default(); + let wei = t_weighted + .remove(host)? + .map(|g| g.value()) + .unwrap_or_default(); + + println!("cleared host {host:?} raw={imp} weighted={wei}"); + } + txn.commit()?; + + Ok(()) +} |