mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Automatically clean up old logs
This commit is contained in:
parent
5a13d7beb3
commit
b20c261c7d
@ -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(())
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
@ -18,3 +19,11 @@ pub fn log_admin_action(admin: AdminID, ip: &str, action: AdminAction) -> Res {
|
||||
.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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user