31 lines
709 B
Rust
31 lines
709 B
Rust
use crate::{config::Config, db::*};
|
|
|
|
use std::time::Duration;
|
|
|
|
pub async fn run_cleaner(config: &Config, dbs: Dbs) {
|
|
let mut last_db_clean = 0;
|
|
loop {
|
|
let time = std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_secs();
|
|
|
|
if time > last_db_clean + 3600 {
|
|
clean_antispam(config, dbs.clone(), time);
|
|
last_db_clean = time;
|
|
}
|
|
|
|
tokio::time::sleep(Duration::from_secs(60)).await;
|
|
}
|
|
}
|
|
|
|
fn clean_antispam(config: &Config, dbs: Dbs, time: u64) {
|
|
for (addr, (last_mutation, _mutation_count)) in
|
|
dbs.client_mutation.iter().filter_map(|o| o.ok())
|
|
{
|
|
if last_mutation + config.antispam_duration < time {
|
|
dbs.client_mutation.remove(&addr).unwrap();
|
|
}
|
|
}
|
|
}
|