From 3871691ea420d2f53554fa3557d458625e51a206 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 19 Jan 2025 15:19:13 +1300 Subject: [PATCH] reduce cpu usage of daily-maintenance task --- app/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/cli.py b/app/cli.py index 48c3d168..e30bb19f 100644 --- a/app/cli.py +++ b/app/cli.py @@ -205,7 +205,8 @@ def register(app): # Ensure accurate community stats for community in Community.query.filter(Community.banned == False).all(): - community.subscriptions_count = CommunityMember.query.filter(CommunityMember.community_id == community.id).count() + community.subscriptions_count = db.session.execute(text('SELECT COUNT(user_id) as c FROM community_member WHERE community_id = :community_id AND is_banned = false'), + {'community_id': community.id}).scalar() community.post_count = db.session.execute(text('SELECT COUNT(id) as c FROM post WHERE deleted is false and community_id = :community_id'), {'community_id': community.id}).scalar() community.post_reply_count = db.session.execute(text('SELECT COUNT(id) as c FROM post_reply WHERE deleted is false and community_id = :community_id'),