Skip to content

Commit

Permalink
Change Track.bind to use trackerId + remoteId (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 authored Jan 23, 2024
1 parent b9053e3 commit 4bec027
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -112,18 +112,16 @@ class TrackMutation {
)

fun bindTrack(input: BindTrackInput): CompletableFuture<BindTrackPayload> {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ object TrackController {
val bind =
handler(
queryParam<Int>("mangaId"),
queryParam<Int>("trackSearchId"),
queryParam<Int>("trackerId"),
queryParam<String>("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)
Expand Down
11 changes: 7 additions & 4 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -346,20 +349,20 @@ 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
// empty
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4bec027

Please sign in to comment.