random-topic-shouts-patch
All checks were successful
Deploy on push / deploy (push) Successful in 25s

This commit is contained in:
2024-02-28 18:11:51 +03:00
parent 129c4bccf4
commit ac1fc151ab
2 changed files with 22 additions and 36 deletions

View File

@@ -121,12 +121,8 @@ def topic_unfollow(follower_id, slug):
@query.field('get_topics_random')
async def get_topics_random(_, info, amount=12):
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)
def get_topics_random(_, _info, amount=12):
q = random_topic_query(amount)
topics = []
with local_session() as session:
@@ -136,16 +132,10 @@ async def get_topics_random(_, info, amount=12):
return topics
def get_random_topic():
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)) > 10)
q = q.order_by(func.random()).limit(1)
with local_session() as session:
r = session.execute(q).first()
if r:
[topic] = r
return topic
return
q = q.having(func.count(distinct(ShoutTopic.shout)) > 2)
q = q.order_by(func.random()).limit(amount)
return q