load-random-topic-fix
All checks were successful
deploy / deploy (push) Successful in 1m30s

This commit is contained in:
2023-12-25 01:06:27 +03:00
parent c236768c07
commit 0ea9f45854
4 changed files with 16 additions and 18 deletions

View File

@@ -417,22 +417,20 @@ async def load_shouts_random_top(_, _info, params):
@query.field("load_shouts_random_topic")
async def load_shouts_random_topic(_, info, limit: int = 10):
topic = get_random_topic()
shouts = []
if topic:
q = (
select(Shout)
.options(
joinedload(Shout.authors),
joinedload(Shout.topics),
)
.join(ShoutTopic, and_(Shout.id == ShoutTopic.shout, ShoutTopic.topic == topic.id))
.filter(and_(Shout.deleted_at.is_(None), Shout.visibility == "public"))
q = (
select(Shout)
.options(
joinedload(Shout.authors),
joinedload(Shout.topics),
)
.filter(and_(Shout.deleted_at.is_(None), Shout.visibility == "public", Shout.topics.any(slug=topic.slug)))
)
q = add_stat_columns(q)
q = add_stat_columns(q)
q = q.group_by(Shout.id).order_by(desc(Shout.created_at)).limit(limit)
q = q.group_by(Shout.id).order_by(desc(Shout.createdAt)).limit(limit)
shouts = get_shouts_from_query(q)
shouts = get_shouts_from_query(q)
return {"topic": topic, "shouts": shouts}