From 01ab912bd9940c7ea191ad2dd0b0dc7b0166c628 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 12 Aug 2023 17:15:06 +0200 Subject: [PATCH] Remove unnecessary "downloadNewChapters" call in "fetchChapters" mutation (#652) Gets already called by "Chapter::fetchChapterList", thus, this is unnecessary. Additionally, "chapters.toList()" and "chapters.map()" have to be called in a transaction block, which they are not, and thus, cause an unhandled exception, breaking the mutation --- .../tachidesk/graphql/mutations/ChapterMutation.kt | 10 +++------- .../kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt index 40dda6b0..ff66e3ef 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt @@ -121,21 +121,17 @@ class ChapterMutation { val (clientMutationId, mangaId) = input return future { - val numberOfCurrentChapters = Chapter.getCountOfMangaChapters(mangaId) Chapter.fetchChapterList(mangaId) - numberOfCurrentChapters - }.thenApply { numberOfCurrentChapters -> + }.thenApply { val chapters = transaction { ChapterTable.select { ChapterTable.manga eq mangaId } .orderBy(ChapterTable.sourceOrder) + .map { ChapterType(it) } } - // download new chapters if settings flag is enabled - Chapter.downloadNewChapters(mangaId, numberOfCurrentChapters, chapters.toList()) - FetchChaptersPayload( clientMutationId = clientMutationId, - chapters = chapters.map { ChapterType(it) } + chapters = chapters ) } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt index 68e83f2c..391e4b28 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt @@ -201,7 +201,7 @@ object Chapter { return chapterList } - fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, newChapters: List) { + private fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, newChapters: List) { // convert numbers to be index based val currentNumberOfChapters = (prevNumberOfChapters - 1).coerceAtLeast(0) val updatedNumberOfChapters = (newChapters.size - 1).coerceAtLeast(0)