From 0d3b184238aa2cbc854303e5ec09231a27bdbf74 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:27:12 +1300 Subject: [PATCH] Ensure accurate community stats --- app/cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/cli.py b/app/cli.py index 1a1e9bce..8b2a3d18 100644 --- a/app/cli.py +++ b/app/cli.py @@ -204,6 +204,12 @@ def register(app): db.session.delete(post) db.session.commit() + # Ensure accurate community stats + for community in Community.query.filter(Community.banned == False).all(): + community.post_count = community.posts.filter(Post.deleted == False).count() + community.post_reply_count = community.replies.filter(PostReply.deleted == False).count() + 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)})