From 724f901bbdbd28fc79a90ed4935fda4415db8207 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 21 Oct 2024 16:57:03 +0300 Subject: [PATCH] community-stat-fixes --- orm/community.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/orm/community.py b/orm/community.py index 3554715b..1a5fc6b6 100644 --- a/orm/community.py +++ b/orm/community.py @@ -3,7 +3,6 @@ import time from sqlalchemy import ARRAY, Column, ForeignKey, Integer, String, distinct, func from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import relationship from orm.author import Author from orm.shout import Shout @@ -59,11 +58,9 @@ class CommunityStats: @property def shouts(self): - from orm.shout import ShoutCommunity - return ( - self.community.session.query(func.count(ShoutCommunity.shout_id)) - .filter(ShoutCommunity.community_id == self.community.id) + self.community.session.query(func.count(Shout.id)) + .filter(Shout.community == self.community.id) .scalar() ) @@ -77,12 +74,12 @@ class CommunityStats: @property def authors(self): - # author has a shout with community id and featured_at is not null + # author has a shout with community id and its featured_at is not null return ( self.community.session.query(func.count(distinct(Author.id))) .join(Shout) .filter( - Shout.community_id == self.community.id, Shout.featured_at.is_not(None), Author.id.in_(Shout.authors) + Shout.community == self.community.id, Shout.featured_at.is_not(None), Author.id.in_(Shout.authors) ) .scalar() )