Apply chapter sync in one transaction

A chapter sync's removals, inserts and updates go through one ChapterRepository.updateFromRemote call, applied atomically. A failure no longer leaves some of a sync's changes written and others missing. Restore folds duplicate chapters in a backup into one before writing, and the chapter deep link looks up the synced chapter afterwards rather than relying on the sync's return value.
This commit is contained in:
AntsyLich
2026-09-27 22:41:55 +06:00
parent 4df0e6b168
commit 6ee529c5aa
6 changed files with 71 additions and 85 deletions
@@ -3,7 +3,6 @@ package tachiyomi.domain.chapter.interactor
import dev.zacsweers.metro.Inject
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.model.ChapterRemoteUpdate
import tachiyomi.domain.chapter.model.ChapterUpdate
import tachiyomi.domain.chapter.repository.ChapterRepository
@@ -27,12 +26,4 @@ class UpdateChapter(
logcat(LogPriority.ERROR, e)
}
}
suspend fun awaitAllRemote(chapterUpdates: List<ChapterRemoteUpdate>) {
try {
chapterRepository.updateAllRemote(chapterUpdates)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}
}
}
@@ -7,15 +7,15 @@ import tachiyomi.domain.chapter.model.ChapterUpdate
interface ChapterRepository {
suspend fun addAll(chapters: List<Chapter>): List<Chapter>
suspend fun update(chapterUpdate: ChapterUpdate)
suspend fun updateAll(chapterUpdates: List<ChapterUpdate>)
suspend fun updateAllRemote(chapterUpdates: List<ChapterRemoteUpdate>)
suspend fun removeChaptersWithIds(chapterIds: List<Long>)
suspend fun updateFromRemote(
removedIds: List<Long>,
added: List<Chapter>,
updated: List<ChapterRemoteUpdate>,
): List<Chapter>
suspend fun getChapterByMangaId(mangaId: Long, applyScanlatorFilter: Boolean = false): List<Chapter>