From 4bec027f113eac78b0686834f0648c2af364fd93 Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Mon, 22 Jan 2024 21:35:56 -0500 Subject: [PATCH] Change Track.bind to use trackerId + remoteId (#842) --- .../tachidesk/graphql/mutations/TrackMutation.kt | 12 +++++------- .../tachidesk/manga/controller/TrackController.kt | 7 ++++--- .../kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt | 11 +++++++---- .../suwayomi/tachidesk/manga/impl/track/Track.kt | 11 +++++++---- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/TrackMutation.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/TrackMutation.kt index 0729995cb..58f6a389b 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/TrackMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/TrackMutation.kt @@ -8,7 +8,6 @@ import suwayomi.tachidesk.graphql.types.TrackerType import suwayomi.tachidesk.manga.impl.track.Track import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager import suwayomi.tachidesk.manga.model.table.TrackRecordTable -import suwayomi.tachidesk.manga.model.table.TrackSearchTable import suwayomi.tachidesk.server.JavalinSetup.future import java.util.concurrent.CompletableFuture @@ -103,7 +102,8 @@ class TrackMutation { data class BindTrackInput( val clientMutationId: String? = null, val mangaId: Int, - val trackSearchId: Int, + val trackerId: Int, + val remoteId: Long, ) data class BindTrackPayload( @@ -112,18 +112,16 @@ class TrackMutation { ) fun bindTrack(input: BindTrackInput): CompletableFuture { - val (clientMutationId, mangaId, trackSearchId) = input + val (clientMutationId, mangaId, trackerId, remoteId) = input return future { Track.bind( mangaId, - trackSearchId, + trackerId, + remoteId, ) val trackRecord = transaction { - val trackerId = - TrackSearchTable.select { TrackSearchTable.id eq trackSearchId } - .first()[TrackSearchTable.trackerId] TrackRecordTable.select { TrackRecordTable.mangaId eq mangaId and (TrackRecordTable.trackerId eq trackerId) }.first() diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/TrackController.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/TrackController.kt index 44518327a..7f247b1fb 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/TrackController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/TrackController.kt @@ -105,15 +105,16 @@ object TrackController { val bind = handler( queryParam("mangaId"), - queryParam("trackSearchId"), + queryParam("trackerId"), + queryParam("remoteId"), documentWith = { withOperation { summary("Track Record Bind") description("Bind a Track Record to a Manga") } }, - behaviorOf = { ctx, mangaId, trackSearchId -> - ctx.future(future { Track.bind(mangaId, trackSearchId) }) + behaviorOf = { ctx, mangaId, trackerId, remoteId -> + ctx.future(future { Track.bind(mangaId, trackerId, remoteId.toLong()) }) }, withResults = { httpCode(HttpCode.OK) 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 daf3cfb4c..26e2bbe2e 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt @@ -50,7 +50,6 @@ import suwayomi.tachidesk.server.serverConfig import java.time.Instant import java.util.TreeSet import java.util.concurrent.TimeUnit -import kotlin.collections.listOf import kotlin.math.max object Chapter { @@ -140,6 +139,10 @@ object Chapter { val numberOfCurrentChapters = getCountOfMangaChapters(mangaId) val chapterList = source.getChapterList(sManga) + if (chapterList.isEmpty()) { + throw Exception("No chapters found") + } + // Recognize number for new chapters. chapterList.forEach { chapter -> (source as? HttpSource)?.prepareNewChapter(chapter, sManga) @@ -346,7 +349,7 @@ object Chapter { } if (mangaCategories.isNotEmpty()) { - var downloadCategoriesMap = Category.getCategoryList().groupBy { it.includeInDownload } + val downloadCategoriesMap = Category.getCategoryList().groupBy { it.includeInDownload } val unsetCategories = downloadCategoriesMap[IncludeOrExclude.UNSET].orEmpty() // We only download if it's in the include list, and not in the exclude list. // Use the unset categories as the included categories if the included categories is @@ -354,12 +357,12 @@ object Chapter { val includedCategories = downloadCategoriesMap[IncludeOrExclude.INCLUDE].orEmpty().ifEmpty { unsetCategories } val excludedCategories = downloadCategoriesMap[IncludeOrExclude.EXCLUDE].orEmpty() // Only download manga that aren't in any excluded categories - val mangaExcludeCategories = mangaCategories.intersect(excludedCategories) + val mangaExcludeCategories = mangaCategories.intersect(excludedCategories.toSet()) if (mangaExcludeCategories.isNotEmpty()) { log.debug { "download excluded by categories: '${mangaExcludeCategories.joinToString("', '") { it.name }}'" } return } - val mangaDownloadCategories = mangaCategories.intersect(includedCategories) + val mangaDownloadCategories = mangaCategories.intersect(includedCategories.toSet()) if (mangaDownloadCategories.isNotEmpty()) { log.debug { "download inluded by categories: '${mangaDownloadCategories.joinToString("', '") { it.name }}'" } } else { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt index 98c8c37bc..d93704d04 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt @@ -137,14 +137,17 @@ object Track { suspend fun bind( mangaId: Int, - trackSearchId: Int, + trackerId: Int, + remoteId: Long, ) { val track = transaction { - TrackSearchTable.select { TrackSearchTable.id eq trackSearchId }.first() - .toTrack(mangaId) + TrackSearchTable.select { + TrackSearchTable.trackerId eq trackerId and + (TrackSearchTable.remoteId eq remoteId) + }.first().toTrack(mangaId) } - val tracker = TrackerManager.getTracker(track.sync_id)!! + val tracker = TrackerManager.getTracker(trackerId)!! val chapter = queryMaxReadChapter(mangaId) val hasReadChapters = chapter != null