Minor tracking cleanups

This commit is contained in:
arkon
2023-12-24 22:25:22 -05:00
parent 6d74a86711
commit 6887d98f15
24 changed files with 64 additions and 69 deletions

View File

@@ -346,12 +346,12 @@ class MangaRestorer(
}
private suspend fun restoreTracking(manga: Manga, backupTracks: List<BackupTracking>) {
val dbTrackBySyncId = getTracks.await(manga.id).associateBy { it.syncId }
val dbTrackByTrackerId = getTracks.await(manga.id).associateBy { it.trackerId }
val (existingTracks, newTracks) = backupTracks
.mapNotNull {
val track = it.getTrackImpl()
val dbTrack = dbTrackBySyncId[track.syncId]
val dbTrack = dbTrackByTrackerId[track.trackerId]
?: // New track
return@mapNotNull track.copy(
id = 0, // Let DB assign new ID
@@ -380,7 +380,7 @@ class MangaRestorer(
existingTracks.forEach { track ->
manga_syncQueries.update(
track.mangaId,
track.syncId,
track.trackerId,
track.remoteId,
track.libraryId,
track.title,

View File

@@ -8,7 +8,7 @@ interface Track : Serializable {
var manga_id: Long
var sync_id: Int
var tracker_id: Int
var remote_id: Long
@@ -40,7 +40,7 @@ interface Track : Serializable {
companion object {
fun create(serviceId: Long): Track = TrackImpl().apply {
sync_id = serviceId.toInt()
tracker_id = serviceId.toInt()
}
}
}

View File

@@ -6,7 +6,7 @@ class TrackImpl : Track {
override var manga_id: Long = 0
override var sync_id: Int = 0
override var tracker_id: Int = 0
override var remote_id: Long = 0

View File

@@ -33,6 +33,4 @@ class TrackerManager {
fun loggedInTrackers() = trackers.filter { it.isLoggedIn }
fun get(id: Long) = trackers.find { it.id == id }
fun hasLoggedIn() = trackers.any { it.isLoggedIn }
}

View File

@@ -8,7 +8,7 @@ class TrackSearch : Track {
override var manga_id: Long = 0
override var sync_id: Int = 0
override var tracker_id: Int = 0
override var remote_id: Long = 0
@@ -47,7 +47,7 @@ class TrackSearch : Track {
other as TrackSearch
if (manga_id != other.manga_id) return false
if (sync_id != other.sync_id) return false
if (tracker_id != other.tracker_id) return false
if (remote_id != other.remote_id) return false
return true
@@ -55,14 +55,14 @@ class TrackSearch : Track {
override fun hashCode(): Int {
var result = manga_id.hashCode()
result = 31 * result + sync_id
result = 31 * result + tracker_id
result = 31 * result + remote_id.hashCode()
return result
}
companion object {
fun create(serviceId: Long): TrackSearch = TrackSearch().apply {
sync_id = serviceId.toInt()
tracker_id = serviceId.toInt()
}
}
}