revert-2-queries-less-price
All checks were successful
Deploy on push / deploy (push) Successful in 25s

This commit is contained in:
2024-02-28 19:24:05 +03:00
parent b99ed1a7d1
commit 31320c9972
2 changed files with 26 additions and 27 deletions

View File

@@ -122,7 +122,11 @@ def topic_unfollow(follower_id, slug):
@query.field('get_topics_random')
def get_topics_random(_, _info, amount=12):
q = random_topic_query(amount)
q = select(Topic)
q = q.join(ShoutTopic)
q = q.group_by(Topic.id)
q = q.having(func.count(distinct(ShoutTopic.shout)) > 2)
q = q.order_by(func.random()).limit(amount)
topics = []
with local_session() as session:
@@ -130,12 +134,3 @@ def get_topics_random(_, _info, amount=12):
topics.append(topic)
return topics
def random_topic_query(amount: int):
q = select(Topic)
q = q.join(ShoutTopic)
q = q.group_by(Topic.id)
q = q.having(func.count(distinct(ShoutTopic.shout)) > 2)
q = q.order_by(func.random()).limit(amount)
return q