reactions-sort-groupby-fix
All checks were successful
deploy / deploy (push) Successful in 1m44s

This commit is contained in:
Untone 2024-01-13 10:27:45 +03:00
parent 3a0683137d
commit 28f1f1cc57
2 changed files with 8 additions and 11 deletions

View File

@ -4,6 +4,7 @@ from os.path import exists
from ariadne import load_schema_from_path, make_executable_schema
from ariadne.asgi import GraphQL
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.ariadne import AriadneIntegration
from sentry_sdk.integrations.redis import RedisIntegration

View File

@ -380,18 +380,14 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
q = apply_reaction_filters(by, q)
q = q.where(Reaction.deleted_at.is_(None))
# group by
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.created_at)
# order by
order_way = asc
order_field = by.get("sort", "").replace("-", "")
if by.get("sort", "").startswith("-"):
order_way = desc
if not order_field:
order_field = "created_at"
order_way = desc
q = q.order_by(order_way(order_field))
order_value = by.get("sort", "-created_at")
order_way = desc if order_value.startswith("-") else asc
order_field = order_value.replace("-", "")
# group by
q = q.group_by(Reaction.id, Author.id, Shout.id, aliased_reaction.created_at, Reaction[order_field]).order_by(
order_way(order_field)
)
# pagination
q = q.limit(limit).offset(offset)