topics-sql-debug

This commit is contained in:
Untone 2023-11-30 13:30:50 +03:00
parent 919aaa951f
commit e2f2dff755
2 changed files with 18 additions and 12 deletions

View File

@ -1,6 +1,7 @@
[0.2.17]
- schema: enum types workaround, ReactionKind, InviteStatus, ShoutVisibility
- schema: Shout.created_by, Shout.updated_by fixes
- schema: Shout.created_by, Shout.updated_by
- schema: Shout.authors can be empty
- resovlers: optimized reacted shouts updates query

View File

@ -23,15 +23,20 @@ def add_topic_stat_columns(q):
q = (
q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic)
.add_columns(func.count(distinct(ShoutTopic.shout)).label("shouts_stat"))
.add_columns(func.count(distinct(ShoutTopic.shout))
.label("shouts_stat"))
.outerjoin(aliased_shout_author, ShoutTopic.shout == aliased_shout_author.shout)
.add_columns(func.count(distinct(aliased_shout_author.author)).label("authors_stat"))
.add_columns(func.count(distinct(aliased_shout_author.author))
.label("authors_stat"))
.outerjoin(aliased_topic_follower)
.add_columns(func.count(distinct(aliased_topic_follower.follower)).label("followers_stat"))
.add_columns(func.count(distinct(aliased_topic_follower.follower))
.label("followers_stat"))
)
q = q.group_by(Topic.id)
print(f"[resolvers.topics] Generated SQL: {str(q)}") # Add this line for debugging
return q
@ -49,14 +54,6 @@ def get_topics_from_query(q):
return topics
def topics_followed_by(author_id):
q = select(Topic)
q = add_topic_stat_columns(q)
q = q.join(TopicFollower).where(TopicFollower.follower == author_id)
return get_topics_from_query(q)
@query.field("get_topics_all")
async def get_topics_all(_, _info):
q = select(Topic)
@ -65,6 +62,14 @@ async def get_topics_all(_, _info):
return get_topics_from_query(q)
def topics_followed_by(author_id):
q = select(Topic)
q = add_topic_stat_columns(q)
q = q.join(TopicFollower).where(TopicFollower.follower == author_id)
return get_topics_from_query(q)
@query.field("get_topics_by_community")
async def get_topics_by_community(_, _info, community_id: int):
q = select(Topic).where(Topic.community == community_id)