1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-10 09:32:48 +00:00

Automatically clean up old logs

This commit is contained in:
2021-07-10 19:17:40 +02:00
parent 5a13d7beb3
commit b20c261c7d
3 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@
//!
//! @author Pierre Hubert
use crate::constants::conservation_policy::ADMIN_ACTIONS_LOG_LIFETIME;
use crate::constants::database_tables_names::ADMIN_LOGS_TABLE;
use crate::data::admin::AdminID;
use crate::data::admin_action_log::AdminAction;
@ -17,4 +18,12 @@ pub fn log_admin_action(admin: AdminID, ip: &str, action: AdminAction) -> Res {
.add_u64("time", time())
.add_str("action", &serde_json::to_string(&action)?)
.insert_drop_result()
}
/// Clean old admin logs
pub fn clean_old_logs() -> Res {
database::DeleteQuery::new(ADMIN_LOGS_TABLE)
.set_custom_where("time < ?")
.add_custom_where_arg_u64(time() - ADMIN_ACTIONS_LOG_LIFETIME.as_secs())
.exec()
}