1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-29 08:46:27 +00:00

Automatically delete old user comments

This commit is contained in:
Pierre HUBERT 2021-02-14 18:49:47 +01:00
parent 7876c37330
commit a537dbcd4d
2 changed files with 29 additions and 7 deletions

View File

@ -6,7 +6,7 @@
use crate::constants::CLEAN_UP_INTERVAL; use crate::constants::CLEAN_UP_INTERVAL;
use crate::data::error::Res; use crate::data::error::Res;
use crate::helpers::{account_helper, likes_helper, notifications_helper, user_helper}; use crate::helpers::{account_helper, comments_helper, likes_helper, notifications_helper, user_helper};
/// Start the maintenance thread /// Start the maintenance thread
pub fn start() -> Res { pub fn start() -> Res {
@ -46,6 +46,9 @@ fn do_clean() -> Res {
// Clean old notifications // Clean old notifications
notifications_helper::clean_old_user_notifications(&user)?; notifications_helper::clean_old_user_notifications(&user)?;
// Clean old comments
comments_helper::clean_old_comments(&user)?;
} }

View File

@ -4,13 +4,13 @@
use crate::constants::database_tables_names::COMMENTS_TABLE; use crate::constants::database_tables_names::COMMENTS_TABLE;
use crate::data::comment::Comment; use crate::data::comment::Comment;
use crate::data::error::{ExecError, ResultBoxError}; use crate::data::error::{ExecError, Res, ResultBoxError};
use crate::data::user::UserID; use crate::data::user::{User, UserID};
use crate::helpers::{database, likes_helper, events_helper}; use crate::helpers::{database, events_helper, likes_helper};
use crate::helpers::likes_helper::LikeType;
use crate::utils::date_utils::mysql_date;
use crate::utils::user_data_utils::user_data_path;
use crate::helpers::events_helper::Event; use crate::helpers::events_helper::Event;
use crate::helpers::likes_helper::LikeType;
use crate::utils::date_utils::{mysql_date, time};
use crate::utils::user_data_utils::user_data_path;
/// Create a new comment. In case of success, this function returns the ID of the created comment /// Create a new comment. In case of success, this function returns the ID of the created comment
pub fn create(c: &Comment) -> ResultBoxError<u64> { pub fn create(c: &Comment) -> ResultBoxError<u64> {
@ -120,3 +120,22 @@ pub fn delete_all_user(user_id: &UserID) -> ResultBoxError {
Ok(()) Ok(())
} }
/// Clean old user comments
pub fn clean_old_comments(user: &User) -> Res {
if user.delete_comments_after < 1 {
return Ok(());
}
let comments = database::QueryInfo::new(COMMENTS_TABLE)
.cond_user_id("ID_personne", &user.id)
.set_custom_where("time_insert < ?")
.add_custom_where_argument_u64(time() - user.delete_comments_after)
.exec(db_to_comment)?;
for comment in comments {
delete(&comment)?;
}
Ok(())
}