This commit is contained in:
2024-04-17 18:32:23 +03:00
parent 937b154c6b
commit c25d7e3ab6
39 changed files with 986 additions and 926 deletions

View File

@@ -14,12 +14,12 @@ def add_community_stat_columns(q):
shout_community_aliased = aliased(ShoutCommunity)
q = q.outerjoin(shout_community_aliased).add_columns(
func.count(distinct(shout_community_aliased.shout)).label('shouts_stat')
func.count(distinct(shout_community_aliased.shout)).label("shouts_stat")
)
q = q.outerjoin(
community_followers, community_followers.author == Author.id
).add_columns(
func.count(distinct(community_followers.follower)).label('followers_stat')
func.count(distinct(community_followers.follower)).label("followers_stat")
)
q = q.group_by(Author.id)
@@ -32,8 +32,8 @@ def get_communities_from_query(q):
with local_session() as session:
for [c, shouts_stat, followers_stat] in session.execute(q):
c.stat = {
'shouts': shouts_stat,
'followers': followers_stat,
"shouts": shouts_stat,
"followers": followers_stat,
# "commented": commented_stat,
}
ccc.append(c)
@@ -72,7 +72,7 @@ def community_unfollow(follower_id, slug):
return False
@query.field('get_communities_all')
@query.field("get_communities_all")
async def get_communities_all(_, _info):
q = select(Author)
q = add_community_stat_columns(q)
@@ -80,7 +80,7 @@ async def get_communities_all(_, _info):
return get_communities_from_query(q)
@query.field('get_community')
@query.field("get_community")
async def get_community(_, _info, slug: str):
q = select(Community).where(Community.slug == slug)
q = add_community_stat_columns(q)