diff --git a/chan-like/src/main.rs b/chan-like/src/main.rs index 34fd387..c1ca549 100644 --- a/chan-like/src/main.rs +++ b/chan-like/src/main.rs @@ -11,7 +11,7 @@ use clap::{App, Arg}; const MAX_DAYS_HELP: &'static str = "Purge messages older than days old -If the value is 0 (default) then messages are not deleted by their age +If the value is 0 then messages are not deleted by their age "; const MSG_LIMIT_HELP: &'static str = "Sets the max number of messages per channel. @@ -42,9 +42,19 @@ async fn remove_old(pool: &Pool, age_limit: i64) -> Result<(), mysql_async::Erro } } async fn remove_maxed(pool: &Pool, max_msg: u64) -> Result<(), mysql_async::Error> { - // grab each channel id - // remove max by group - // ? + + // For N channels we're going to do n+1 queries making this really expensive + // TODO: reduce this to a single query for reasons below: tags[network, sql, slow] + /* + * Multiple network hits blow(moreso if the the db is located away from the + * main server binary but i digress. + * The first hit is no the expensive part if I'm being honest, + * It's everything after that leverages the channel id's as the messages + * table is likely to be filled with a ton of shit. + * + * The trick is going to be in some really nasty group by/limit thing but + * frankly this works for now so into the backlog it goes + */ let mut conn = pool.get_conn().await?; let channel_ids: Vec = conn.exec_map( "SELECT id FROM channels", (), @@ -81,8 +91,7 @@ async fn main() -> Result<(), String>{ .long("max-days") .value_name("D") .takes_value(true) - .long_help(MAX_DAYS_HELP) - .default_value("0")) + .long_help(MAX_DAYS_HELP)) .arg(Arg::with_name("config_file") .short("f") .long("file")