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:
@ -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()
|
||||
}
|
Reference in New Issue
Block a user