array_agg
Some checks failed
Deploy on push / deploy (push) Failing after 8s

This commit is contained in:
Untone 2024-08-07 14:22:24 +03:00
parent 572f63f12b
commit 56c010975c

View File

@ -49,34 +49,34 @@ def query_shouts():
) )
).label("rating_stat"), ).label("rating_stat"),
func.max(aliased_reaction.created_at).label("last_reacted_at"), func.max(aliased_reaction.created_at).label("last_reacted_at"),
func.json_agg( func.array_agg(
func.json_build_object( func.distinct(
"id", func.json_build_object(
Author.id, "id",
"name", Author.id,
Author.name, "name",
"slug", Author.name,
Author.slug, "slug",
"pic", Author.slug,
Author.pic, "pic",
Author.pic,
)
) )
) ).label("authors"),
.filter(Author.id.is_not(None)) func.array_agg(
.label("authors"), func.distinct(
func.json_agg( func.json_build_object(
func.json_build_object( "id",
"id", Topic.id,
Topic.id, "title",
"title", Topic.title,
Topic.title, "body",
"body", Topic.body,
Topic.body, "slug",
"slug", Topic.slug,
Topic.slug, )
) )
) ).label("topics"),
.filter(Topic.id.is_not(None))
.label("topics"),
) )
.outerjoin(aliased_reaction, aliased_reaction.shout == Shout.id) .outerjoin(aliased_reaction, aliased_reaction.shout == Shout.id)
.outerjoin(shout_author, shout_author.shout == Shout.id) .outerjoin(shout_author, shout_author.shout == Shout.id)
@ -84,7 +84,7 @@ def query_shouts():
.outerjoin(shout_topic, shout_topic.shout == Shout.id) .outerjoin(shout_topic, shout_topic.shout == Shout.id)
.outerjoin(Topic, Topic.id == shout_topic.topic) .outerjoin(Topic, Topic.id == shout_topic.topic)
.where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None))) .where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None)))
.group_by(Shout.id, Author.id, Topic.id) .group_by(Shout.id)
) )
return q, aliased_reaction return q, aliased_reaction