last_commented_at
All checks were successful
Deploy on push / deploy (push) Successful in 8s

This commit is contained in:
Untone 2024-12-04 17:40:45 +03:00
parent a71a6fcc41
commit 597fd6ad55
3 changed files with 8 additions and 6 deletions

View File

@ -161,7 +161,9 @@ def query_with_stat(info):
) )
.filter(Reaction.reply_to.is_(None)) .filter(Reaction.reply_to.is_(None))
.label("rating"), .label("rating"),
func.max(Reaction.created_at).filter(Reaction.reply_to.is_(None)).label("last_reacted_at"), func.max(Reaction.created_at).filter(Reaction.kind == ReactionKind.COMMENT.value).label(
"last_commented_at"
),
) )
.where(Reaction.deleted_at.is_(None)) .where(Reaction.deleted_at.is_(None))
.group_by(Reaction.shout) .group_by(Reaction.shout)
@ -174,7 +176,8 @@ def query_with_stat(info):
func.coalesce(stats_subquery.c.comments_count, 0), func.coalesce(stats_subquery.c.comments_count, 0),
"rating", "rating",
func.coalesce(stats_subquery.c.rating, 0), func.coalesce(stats_subquery.c.rating, 0),
"last_reacted_at", "last_commented_at",
func.coalesce(stats_subquery.c.last_commented_at, 0),
None, None,
).label("stat") ).label("stat")
) )
@ -326,7 +329,7 @@ def apply_sorting(q, options):
Применение сортировки с сохранением порядка Применение сортировки с сохранением порядка
""" """
order_str = options.get("order_by") order_str = options.get("order_by")
if order_str in ["rating", "comments_count", "last_reacted_at"]: if order_str in ["rating", "comments_count", "last_commented_at"]:
query_order_by = desc(text(order_str)) if options.get("order_by_desc", True) else asc(text(order_str)) query_order_by = desc(text(order_str)) if options.get("order_by_desc", True) else asc(text(order_str))
q = q.distinct(text(order_str), Shout.id).order_by( # DISTINCT ON включает поле сортировки q = q.distinct(text(order_str), Shout.id).order_by( # DISTINCT ON включает поле сортировки
nulls_last(query_order_by), Shout.id nulls_last(query_order_by), Shout.id

View File

@ -14,7 +14,7 @@ enum ReactionSort {
} }
enum ShoutsOrderBy { enum ShoutsOrderBy {
last_reacted_at last_commented_at
rating rating
comments_count comments_count
} }

View File

@ -110,8 +110,7 @@ type Stat {
rating: Int rating: Int
commented: Int commented: Int
viewed: Int viewed: Int
# followed: Int last_commented_at: Int
last_reacted_at: Int
} }
type CommunityStat { type CommunityStat {