mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-20 15:42:27 -07:00
Update an existing track in place instead of replacing it
Upserting a track for an entry and tracker that already have one updates that row, instead of the table's REPLACE deleting it and inserting a new one under a new id. Anything keyed to the old id, such as a queued tracking update, keeps working. The query, repository methods and interactor are renamed from insert to upsert to say so.
This commit is contained in:
@@ -272,7 +272,7 @@ class RestoreRepositoryImpl(
|
||||
.partition { it.id > 0 }
|
||||
|
||||
if (newTracks.isNotEmpty()) {
|
||||
trackRepository.insertAll(newTracks)
|
||||
trackRepository.upsertAll(newTracks)
|
||||
}
|
||||
|
||||
existingTracks.forEach { track ->
|
||||
|
||||
@@ -50,18 +50,18 @@ class TrackRepositoryImpl(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun insert(track: Track) {
|
||||
insertValues(track)
|
||||
override suspend fun upsert(track: Track) {
|
||||
upsertValues(track)
|
||||
}
|
||||
|
||||
override suspend fun insertAll(tracks: List<Track>) {
|
||||
insertValues(*tracks.toTypedArray())
|
||||
override suspend fun upsertAll(tracks: List<Track>) {
|
||||
upsertValues(*tracks.toTypedArray())
|
||||
}
|
||||
|
||||
private suspend fun insertValues(vararg tracks: Track) {
|
||||
private suspend fun upsertValues(vararg tracks: Track) {
|
||||
database.transaction {
|
||||
tracks.forEach { mangaTrack ->
|
||||
database.manga_syncQueries.insert(
|
||||
database.manga_syncQueries.upsert(
|
||||
mangaId = mangaTrack.mangaId,
|
||||
syncId = mangaTrack.trackerId,
|
||||
remoteId = mangaTrack.remoteId,
|
||||
|
||||
Reference in New Issue
Block a user