From 64a6180a13e98294d5a8c9825bbe273939f1ba0d Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:31:04 +1200 Subject: [PATCH] move content deletion to be earlier in the daily maintenance script --- app/cli.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/cli.py b/app/cli.py index a7ce8d52..a242d1aa 100644 --- a/app/cli.py +++ b/app/cli.py @@ -191,6 +191,19 @@ def register(app): tag.post_count = post_count db.session.commit() + # Delete soft-deleted content after 7 days + for post_reply in PostReply.query.filter(PostReply.deleted == True, + PostReply.posted_at < utcnow() - timedelta(days=7)).all(): + post_reply.delete_dependencies() + db.session.delete(post_reply) + + for post in Post.query.filter(Post.deleted == True, + Post.posted_at < utcnow() - timedelta(days=7)).all(): + post.delete_dependencies() + db.session.delete(post) + + db.session.commit() + # Check for dormant or dead instances instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all() HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'} @@ -284,16 +297,6 @@ def register(app): InstanceRole.role == 'admin').delete() db.session.commit() - # Delete soft-deleted content after 7 days - for post_reply in PostReply.query.filter(PostReply.deleted == True, PostReply.posted_at < utcnow() - timedelta(days=7)).all(): - db.session.delete(post_reply) - - for post in Post.query.filter(Post.deleted == True, Post.posted_at < utcnow() - timedelta(days=7)).all(): - post.delete_dependencies() - db.session.delete(post) - - db.session.commit() - @app.cli.command("spaceusage") def spaceusage(): with app.app_context():