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
This commit is contained in:
schroda
2023-08-12 17:15:06 +02:00
committed by GitHub
parent 557bad60bc
commit 01ab912bd9
2 changed files with 4 additions and 8 deletions

View File

@@ -121,21 +121,17 @@ class ChapterMutation {
val (clientMutationId, mangaId) = input val (clientMutationId, mangaId) = input
return future { return future {
val numberOfCurrentChapters = Chapter.getCountOfMangaChapters(mangaId)
Chapter.fetchChapterList(mangaId) Chapter.fetchChapterList(mangaId)
numberOfCurrentChapters }.thenApply {
}.thenApply { numberOfCurrentChapters ->
val chapters = transaction { val chapters = transaction {
ChapterTable.select { ChapterTable.manga eq mangaId } ChapterTable.select { ChapterTable.manga eq mangaId }
.orderBy(ChapterTable.sourceOrder) .orderBy(ChapterTable.sourceOrder)
.map { ChapterType(it) }
} }
// download new chapters if settings flag is enabled
Chapter.downloadNewChapters(mangaId, numberOfCurrentChapters, chapters.toList())
FetchChaptersPayload( FetchChaptersPayload(
clientMutationId = clientMutationId, clientMutationId = clientMutationId,
chapters = chapters.map { ChapterType(it) } chapters = chapters
) )
} }
} }

View File

@@ -201,7 +201,7 @@ object Chapter {
return chapterList return chapterList
} }
fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, newChapters: List<ResultRow>) { private fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, newChapters: List<ResultRow>) {
// convert numbers to be index based // convert numbers to be index based
val currentNumberOfChapters = (prevNumberOfChapters - 1).coerceAtLeast(0) val currentNumberOfChapters = (prevNumberOfChapters - 1).coerceAtLeast(0)
val updatedNumberOfChapters = (newChapters.size - 1).coerceAtLeast(0) val updatedNumberOfChapters = (newChapters.size - 1).coerceAtLeast(0)