move content deletion to be earlier in the daily maintenance script

This commit is contained in:
rimu 2024-08-15 20:31:04 +12:00
parent 2c362e32f4
commit 64a6180a13

View file

@ -191,6 +191,19 @@ def register(app):
tag.post_count = post_count tag.post_count = post_count
db.session.commit() 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 # Check for dormant or dead instances
instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all() instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all()
HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'} HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'}
@ -284,16 +297,6 @@ def register(app):
InstanceRole.role == 'admin').delete() InstanceRole.role == 'admin').delete()
db.session.commit() 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") @app.cli.command("spaceusage")
def spaceusage(): def spaceusage():
with app.app_context(): with app.app_context():