topics-sql-debug
This commit is contained in:
parent
919aaa951f
commit
e2f2dff755
|
@ -1,6 +1,7 @@
|
||||||
[0.2.17]
|
[0.2.17]
|
||||||
- schema: enum types workaround, ReactionKind, InviteStatus, ShoutVisibility
|
- 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
|
- resovlers: optimized reacted shouts updates query
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,20 @@ def add_topic_stat_columns(q):
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic)
|
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)
|
.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)
|
.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)
|
q = q.group_by(Topic.id)
|
||||||
|
|
||||||
|
print(f"[resolvers.topics] Generated SQL: {str(q)}") # Add this line for debugging
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,14 +54,6 @@ def get_topics_from_query(q):
|
||||||
return topics
|
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")
|
@query.field("get_topics_all")
|
||||||
async def get_topics_all(_, _info):
|
async def get_topics_all(_, _info):
|
||||||
q = select(Topic)
|
q = select(Topic)
|
||||||
|
@ -65,6 +62,14 @@ async def get_topics_all(_, _info):
|
||||||
return get_topics_from_query(q)
|
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")
|
@query.field("get_topics_by_community")
|
||||||
async def get_topics_by_community(_, _info, community_id: int):
|
async def get_topics_by_community(_, _info, community_id: int):
|
||||||
q = select(Topic).where(Topic.community == community_id)
|
q = select(Topic).where(Topic.community == community_id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user