This commit is contained in:
Untone 2024-11-01 21:39:05 +03:00
parent c78347b6f9
commit d40728aec9

View File

@ -74,7 +74,10 @@ def query_with_stat(info):
q = q.join(main_author, main_author.id == Shout.created_by) q = q.join(main_author, main_author.id == Shout.created_by)
q = q.add_columns( q = q.add_columns(
json_builder( json_builder(
"id", main_author.id, "name", main_author.name, "slug", main_author.slug, "pic", main_author.pic "id", main_author.id,
"name", main_author.name,
"slug", main_author.slug,
"pic", main_author.pic
).label("main_author") ).label("main_author")
) )
@ -107,16 +110,11 @@ def query_with_stat(info):
select( select(
json_array_builder( json_array_builder(
json_builder( json_builder(
"id", "id", Author.id,
Author.id, "name", Author.name,
"name", "slug", Author.slug,
Author.name, "pic", Author.pic,
"slug", "caption", ShoutAuthor.caption,
Author.slug,
"pic",
Author.pic,
"caption",
ShoutAuthor.caption,
) )
).label("authors") ).label("authors")
) )
@ -158,18 +156,15 @@ def query_with_stat(info):
# aggregate in one column # aggregate in one column
q = q.add_columns( q = q.add_columns(
json_builder( json_builder(
"comments_count", "comments_count", stats_subquery.c.comments_count,
stats_subquery.c.comments_count, "rating", stats_subquery.c.rating,
"rating", "last_reacted_at", stats_subquery.c.last_reacted_at,
stats_subquery.c.rating,
"last_reacted_at",
stats_subquery.c.last_reacted_at,
).label("stat") ).label("stat")
) )
# Фильтр опубликованных # Фильтр опубликованных
q = q.where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None))) q = q.where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None)))
q = q.group_by(Shout.id, Author.id) q = q.group_by(Shout.id, main_author.id, main_topic.id)
return q return q