From 80f431be9ff3022a67ebdeb36d59c0e3aa45483e Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 16 Jul 2023 22:58:41 +0200 Subject: [PATCH] Add function to get number of manga chapters --- .../tachidesk/graphql/mutations/ChapterMutation.kt | 2 +- .../main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt | 7 +++++-- 2 files changed, 6 insertions(+), 3 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 9ba8bc0c5..5361830ce 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt @@ -122,7 +122,7 @@ class ChapterMutation { val (clientMutationId, mangaId) = input return future { - val numberOfCurrentChapters = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count().toInt() } + val numberOfCurrentChapters = Chapter.getCountOfMangaChapters(mangaId) Chapter.fetchChapterList(mangaId) numberOfCurrentChapters }.thenApply { numberOfCurrentChapters -> 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 b57af9994..14a68e4cb 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt @@ -62,6 +62,10 @@ object Chapter { } } + fun getCountOfMangaChapters(mangaId: Int): Int { + return transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count().toInt() } + } + private suspend fun getSourceChapters(mangaId: Int): List { val chapterList = fetchChapterList(mangaId) @@ -113,8 +117,7 @@ object Chapter { url = manga.url } - val numberOfCurrentChapters = - transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count().toInt() } + val numberOfCurrentChapters = getCountOfMangaChapters(mangaId) val chapterList = source.fetchChapterList(sManga).awaitSingle() // Recognize number for new chapters.