mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-16 13:48:09 -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,
|
||||
|
||||
@@ -40,9 +40,24 @@ SELECT *
|
||||
FROM manga_sync
|
||||
WHERE manga_id = :mangaId;
|
||||
|
||||
insert:
|
||||
upsert:
|
||||
INSERT INTO manga_sync(manga_id,sync_id,remote_id,library_id,title,last_chapter_read,total_chapters,status,score,remote_url,start_date,finish_date,private)
|
||||
VALUES (:mangaId,:syncId,:remoteId,:libraryId,:title,:lastChapterRead,:totalChapters,:status,:score,:remoteUrl,:startDate,:finishDate,:private);
|
||||
VALUES (:mangaId,:syncId,:remoteId,:libraryId,:title,:lastChapterRead,:totalChapters,:status,:score,:remoteUrl,:startDate,:finishDate,:private)
|
||||
ON CONFLICT(manga_id, sync_id)
|
||||
DO UPDATE
|
||||
SET
|
||||
remote_id = :remoteId,
|
||||
library_id = :libraryId,
|
||||
title = :title,
|
||||
last_chapter_read = :lastChapterRead,
|
||||
total_chapters = :totalChapters,
|
||||
status = :status,
|
||||
score = :score,
|
||||
remote_url = :remoteUrl,
|
||||
start_date = :startDate,
|
||||
finish_date = :finishDate,
|
||||
private = :private
|
||||
WHERE manga_id = :mangaId AND sync_id = :syncId;
|
||||
|
||||
update:
|
||||
UPDATE manga_sync
|
||||
|
||||
Reference in New Issue
Block a user