1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Automatically clean up old logs

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

View File

@ -6,7 +6,7 @@
use crate::constants::{CLEAN_UP_INTERVAL, INITIAL_REFRESH_LOAD_INTERVAL}; use crate::constants::{CLEAN_UP_INTERVAL, INITIAL_REFRESH_LOAD_INTERVAL};
use crate::data::error::Res; 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 /// Start the maintenance thread
pub fn start() -> Res { pub fn start() -> Res {
@ -63,6 +63,8 @@ fn do_clean() -> Res {
account_helper::remove_if_inactive_for_too_long_time(&user)?; account_helper::remove_if_inactive_for_too_long_time(&user)?;
} }
// Clean up old admin actions
admin_log_helper::clean_old_logs()?;
Ok(()) Ok(())
} }

View File

@ -115,6 +115,9 @@ pub mod conservation_policy {
/// Minimum likes lifetime (1 month) /// Minimum likes lifetime (1 month)
pub const MIN_LIKES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30); 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 /// WebSocket access token lifetime, in seconds

View File

@ -2,6 +2,7 @@
//! //!
//! @author Pierre Hubert //! @author Pierre Hubert
use crate::constants::conservation_policy::ADMIN_ACTIONS_LOG_LIFETIME;
use crate::constants::database_tables_names::ADMIN_LOGS_TABLE; use crate::constants::database_tables_names::ADMIN_LOGS_TABLE;
use crate::data::admin::AdminID; use crate::data::admin::AdminID;
use crate::data::admin_action_log::AdminAction; use crate::data::admin_action_log::AdminAction;
@ -18,3 +19,11 @@ pub fn log_admin_action(admin: AdminID, ip: &str, action: AdminAction) -> Res {
.add_str("action", &serde_json::to_string(&action)?) .add_str("action", &serde_json::to_string(&action)?)
.insert_drop_result() .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()
}