Skip to content

Commit

Permalink
Handle missing track search results on bind (#1196)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schroda authored Dec 11, 2024
1 parent b58fc39 commit de94244
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)!!

Expand Down

0 comments on commit de94244

Please sign in to comment.