From de942440e3dbd81207f048a1d13a5fbdb4a1c73c Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 11 Dec 2024 01:50:16 +0100 Subject: [PATCH] Handle missing track search results on bind (#1196) It's possible that a manga is bound to a tracker while there is no search result. This happens when e.g. restoring a backup which includes track bindings for which there was never a tracker search. In that case when trying to e.g. copy the binding to another manga, the mutation would fail due to not finding a search result. These cases can be handled by additionally checking the TrackRecordTable to get the necessary track info. --- .../suwayomi/tachidesk/manga/impl/track/Track.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 b0d65452d..55d693b89 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 @@ -122,7 +122,7 @@ object Track { } } - private fun ResultRow.toTrack(mangaId: Int): Track = + private fun ResultRow.toTrackFromSearch(mangaId: Int): Track = Track.create(this[TrackSearchTable.trackerId]).also { it.manga_id = mangaId it.media_id = this[TrackSearchTable.remoteId] @@ -143,8 +143,18 @@ object Track { .where { TrackSearchTable.trackerId eq trackerId and (TrackSearchTable.remoteId eq remoteId) - }.first() - .toTrack(mangaId) + }.firstOrNull() + ?.toTrackFromSearch(mangaId) + ?: TrackRecordTable + .selectAll() + .where { + (TrackRecordTable.trackerId eq trackerId) and + (TrackRecordTable.remoteId eq remoteId) + }.first() + .toTrack() + .apply { + manga_id = mangaId + } } val tracker = TrackerManager.getTracker(trackerId)!!