From cbf44ef2294cb25ccea992b8b98c3243f24ab57e Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:50:11 +1300 Subject: [PATCH] Delete voting data after 6 months --- app/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/cli.py b/app/cli.py index 4b22c811..ac20c847 100644 --- a/app/cli.py +++ b/app/cli.py @@ -10,9 +10,7 @@ import flask import httpx from flask import json, current_app from flask_babel import _ -from requests import JSONDecodeError from sqlalchemy import or_, desc, text -from sqlalchemy.orm import configure_mappers from app import db import click @@ -203,7 +201,11 @@ def register(app): Post.posted_at < utcnow() - timedelta(days=7)).all(): post.delete_dependencies() db.session.delete(post) + db.session.commit() + # Delete voting data after 6 months + db.session.execute(text('DELETE FROM "post_vote" WHERE created_at < :cutoff'), {'cutoff': utcnow() - timedelta(days=28 * 6)}) + db.session.execute(text('DELETE FROM "post_reply_vote" WHERE created_at < :cutoff'), {'cutoff': utcnow() - timedelta(days=28 * 6)}) db.session.commit() # Check for dormant or dead instances