media-item-type
All checks were successful
Deploy on push / deploy (push) Successful in 6s

This commit is contained in:
Untone 2024-11-01 21:03:09 +03:00
parent fba0f34020
commit f495953f6a
2 changed files with 17 additions and 4 deletions

View File

@ -61,7 +61,12 @@ def query_with_stat(info):
:param info: Информация о контексте GraphQL
:return: Запрос с подзапросом статистики.
"""
q = select(Shout).group_by(Shout.id)
# Основной запрос без GROUP BY
q = (
select(Shout)
.distinct(Shout.id)
.join(Author, Author.id == Shout.created_by)
)
# Создаем алиасы для всех таблиц
main_author = aliased(Author)
@ -321,9 +326,9 @@ def apply_sorting(q, options):
# Сортировка по выбранному статистическому полю в указанном порядке
query_order_by = desc(text(order_str)) if options.get("order_by_desc", True) else asc(text(order_str))
# Применение сортировки с размещением NULL значений в конце
q = q.order_by(nulls_last(query_order_by))
q = q.order_by(Shout.id, nulls_last(query_order_by))
else:
q = q.order_by(Shout.published_at.desc())
q = q.order_by(Shout.id, Shout.published_at.desc())
return q

View File

@ -57,6 +57,14 @@ type Reaction {
# old_thread: String
}
type MediaItem {
url: String
pic: String
title: String
body: String
artist: String
}
type Shout {
id: Int!
title: String!
@ -87,7 +95,7 @@ type Shout {
version_of: Shout # TODO: use version_of somewhere
media: String
media: [MediaItem]
stat: Stat
score: Float
}