Fix sorting of gql mangas query (#2043)

Regression fbb383b1f1

Broke sorting due to ordering the manga by their id first, thus, the other orderings were never applied
This commit is contained in:
schroda
2026-05-17 02:16:27 +02:00
committed by GitHub
parent fbb383b1f1
commit 41bb6d3dc1

View File

@@ -15,9 +15,11 @@ import org.jetbrains.exposed.v1.core.Op
import org.jetbrains.exposed.v1.core.SortOrder import org.jetbrains.exposed.v1.core.SortOrder
import org.jetbrains.exposed.v1.core.greater import org.jetbrains.exposed.v1.core.greater
import org.jetbrains.exposed.v1.core.inList import org.jetbrains.exposed.v1.core.inList
import org.jetbrains.exposed.v1.core.inSubQuery
import org.jetbrains.exposed.v1.core.less import org.jetbrains.exposed.v1.core.less
import org.jetbrains.exposed.v1.core.like import org.jetbrains.exposed.v1.core.like
import org.jetbrains.exposed.v1.jdbc.select import org.jetbrains.exposed.v1.jdbc.select
import org.jetbrains.exposed.v1.jdbc.selectAll
import org.jetbrains.exposed.v1.jdbc.transactions.transaction import org.jetbrains.exposed.v1.jdbc.transactions.transaction
import suwayomi.tachidesk.graphql.directives.RequireAuth import suwayomi.tachidesk.graphql.directives.RequireAuth
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
@@ -243,22 +245,18 @@ class MangaQuery {
): MangaNodeList { ): MangaNodeList {
val queryResults = val queryResults =
transaction { transaction {
val res = val mangaIdsQuery =
MangaTable MangaTable
.leftJoin(CategoryMangaTable) .leftJoin(CategoryMangaTable)
.select(MangaTable.columns) .select(MangaTable.id)
.withDistinct()
val applySorting = order != null || orderBy != null || (last != null || before != null) mangaIdsQuery.applyOps(condition, filter)
if (applySorting) { val res =
res.withDistinctOn(MangaTable.id to SortOrder.ASC) MangaTable.selectAll().where { MangaTable.id inSubQuery mangaIdsQuery }
} else {
res.withDistinctOn(MangaTable.id)
}
res.applyOps(condition, filter) if (order != null || orderBy != null || (last != null || before != null)) {
if (applySorting) {
val baseSort = listOf(MangaOrder(MangaOrderBy.ID, SortOrder.ASC)) val baseSort = listOf(MangaOrder(MangaOrderBy.ID, SortOrder.ASC))
val deprecatedSort = listOfNotNull(orderBy?.let { MangaOrder(orderBy, orderByType) }) val deprecatedSort = listOfNotNull(orderBy?.let { MangaOrder(orderBy, orderByType) })
val actualSort = (order.orEmpty() + deprecatedSort + baseSort) val actualSort = (order.orEmpty() + deprecatedSort + baseSort)