diff --git a/src/cleanup_thread.rs b/src/cleanup_thread.rs index 8b66f3e..b76d746 100644 --- a/src/cleanup_thread.rs +++ b/src/cleanup_thread.rs @@ -6,7 +6,7 @@ use crate::constants::{CLEAN_UP_INTERVAL, INITIAL_REFRESH_LOAD_INTERVAL}; use crate::data::error::Res; -use crate::helpers::{account_helper, comments_helper, conversations_helper, likes_helper, notifications_helper, posts_helper, user_helper}; +use crate::helpers::{account_helper, comments_helper, conversations_helper, likes_helper, notifications_helper, posts_helper, user_helper, admin_log_helper}; /// Start the maintenance thread pub fn start() -> Res { @@ -63,6 +63,8 @@ fn do_clean() -> Res { account_helper::remove_if_inactive_for_too_long_time(&user)?; } + // Clean up old admin actions + admin_log_helper::clean_old_logs()?; Ok(()) } \ No newline at end of file diff --git a/src/constants.rs b/src/constants.rs index cef8ba9..8815d29 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -115,6 +115,9 @@ pub mod conservation_policy { /// Minimum likes lifetime (1 month) pub const MIN_LIKES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30); + + /// Admin actions log duration (3 months) + pub const ADMIN_ACTIONS_LOG_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30 * 3); } /// WebSocket access token lifetime, in seconds diff --git a/src/helpers/admin_log_helper.rs b/src/helpers/admin_log_helper.rs index 22a3645..54f1982 100644 --- a/src/helpers/admin_log_helper.rs +++ b/src/helpers/admin_log_helper.rs @@ -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() } \ No newline at end of file