CommentUpdateForm,
},
traits::{Crud, Likeable, Saveable},
- utils::{get_conn, naive_now, DbPool},
+ utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT},
};
use diesel::{
dsl::{insert_into, sql_query},
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
+
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
.set((
- content.eq("*Permananently Deleted*"),
+ content.eq(DELETED_REPLACEMENT_TEXT),
deleted.eq(true),
updated.eq(naive_now()),
))
PostUpdateForm,
},
traits::{Crud, Likeable, Readable, Saveable},
- utils::{get_conn, naive_now, DbPool, FETCH_LIMIT_MAX},
+ utils::{
+ get_conn,
+ naive_now,
+ DbPool,
+ DELETED_REPLACEMENT_TEXT,
+ DELETED_REPLACEMENT_URL,
+ FETCH_LIMIT_MAX,
+ },
};
use ::url::Url;
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
- let perma_deleted = "*Permananently Deleted*";
- let perma_deleted_url = "https://deleted.com";
-
diesel::update(post.filter(creator_id.eq(for_creator_id)))
.set((
- name.eq(perma_deleted),
- url.eq(perma_deleted_url),
- body.eq(perma_deleted),
+ name.eq(DELETED_REPLACEMENT_TEXT),
+ url.eq(DELETED_REPLACEMENT_URL),
+ body.eq(DELETED_REPLACEMENT_TEXT),
deleted.eq(true),
updated.eq(naive_now()),
))
dsl::{now, IntervalDsl},
Connection,
ExpressionMethods,
+ NullableExpressionMethods,
QueryDsl,
};
// Import week days and WeekDay
use lemmy_db_schema::{
schema::{
activity,
+ comment,
comment_aggregates,
community_aggregates,
community_person_ban,
instance,
person,
+ post,
post_aggregates,
},
source::instance::{Instance, InstanceForm},
- utils::{functions::hot_rank, naive_now},
+ utils::{functions::hot_rank, naive_now, DELETED_REPLACEMENT_TEXT},
};
use lemmy_routes::nodeinfo::NodeInfo;
use lemmy_utils::{error::LemmyError, REQWEST_TIMEOUT};
context_1.settings_updated_channel().remove_older_than(hour);
});
+ // Overwrite deleted & removed posts and comments every day
+ let url = db_url.clone();
+ scheduler.every(CTimeUnits::days(1)).run(move || {
+ let mut conn = PgConnection::establish(&url).expect("could not establish connection");
+ overwrite_deleted_posts_and_comments(&mut conn);
+ });
+
// Update the Instance Software
scheduler.every(CTimeUnits::days(1)).run(move || {
let mut conn = PgConnection::establish(&db_url).expect("could not establish connection");
update_hot_ranks(&mut conn, false);
update_banned_when_expired(&mut conn);
clear_old_activities(&mut conn);
+ overwrite_deleted_posts_and_comments(&mut conn);
}
/// Update the hot_rank columns for the aggregates tables
}
}
+/// overwrite posts and comments 30d after deletion
+fn overwrite_deleted_posts_and_comments(conn: &mut PgConnection) {
+ info!("Overwriting deleted posts...");
+ match diesel::update(
+ post::table
+ .filter(post::deleted.eq(true))
+ .filter(post::updated.lt(now.nullable() - 1.months()))
+ .filter(post::body.ne(DELETED_REPLACEMENT_TEXT)),
+ )
+ .set((
+ post::body.eq(DELETED_REPLACEMENT_TEXT),
+ post::name.eq(DELETED_REPLACEMENT_TEXT),
+ ))
+ .execute(conn)
+ {
+ Ok(_) => {
+ info!("Done.");
+ }
+ Err(e) => {
+ error!("Failed to overwrite deleted posts: {}", e)
+ }
+ }
+
+ info!("Overwriting deleted comments...");
+ match diesel::update(
+ comment::table
+ .filter(comment::deleted.eq(true))
+ .filter(comment::updated.lt(now.nullable() - 1.months()))
+ .filter(comment::content.ne(DELETED_REPLACEMENT_TEXT)),
+ )
+ .set(comment::content.eq(DELETED_REPLACEMENT_TEXT))
+ .execute(conn)
+ {
+ Ok(_) => {
+ info!("Done.");
+ }
+ Err(e) => {
+ error!("Failed to overwrite deleted comments: {}", e)
+ }
+ }
+}
+
/// Re-calculate the site and community active counts every 12 hours
fn active_counts(conn: &mut PgConnection) {
info!("Updating active site and community aggregates ...");