History url is not globally unique

This commit is contained in:
Jobobby04 2024-03-17 19:52:38 -04:00
parent 911e959fcf
commit 983a80ba42
2 changed files with 6 additions and 5 deletions

View File

@ -313,7 +313,7 @@ class MangaRestorer(
restoreCategories(manga, categories, backupCategories) restoreCategories(manga, categories, backupCategories)
restoreChapters(manga, chapters) restoreChapters(manga, chapters)
restoreTracking(manga, tracks) restoreTracking(manga, tracks)
restoreHistory(history) restoreHistory(manga, history)
restoreExcludedScanlators(manga, excludedScanlators) restoreExcludedScanlators(manga, excludedScanlators)
updateManga.awaitUpdateFetchInterval(manga, now, currentFetchWindow) updateManga.awaitUpdateFetchInterval(manga, now, currentFetchWindow)
// SY --> // SY -->
@ -359,13 +359,14 @@ class MangaRestorer(
} }
} }
private suspend fun restoreHistory(backupHistory: List<BackupHistory>) { private suspend fun restoreHistory(manga: Manga, backupHistory: List<BackupHistory>) {
val toUpdate = backupHistory.mapNotNull { history -> val toUpdate = backupHistory.mapNotNull { history ->
val dbHistory = handler.awaitOneOrNull { historyQueries.getHistoryByChapterUrl(history.url) } val dbHistory = handler.awaitOneOrNull { historyQueries.getHistoryByChapterUrl(manga.id, history.url) }
val item = history.getHistoryImpl() val item = history.getHistoryImpl()
if (dbHistory == null) { if (dbHistory == null) {
val chapter = handler.awaitOneOrNull { chaptersQueries.getChapterByUrl(history.url) } val chapter = handler.awaitList { chaptersQueries.getChapterByUrl(history.url) }
.find { it.manga_id == manga.id }
return@mapNotNull if (chapter == null) { return@mapNotNull if (chapter == null) {
// Chapter doesn't exist; skip // Chapter doesn't exist; skip
null null

View File

@ -31,7 +31,7 @@ H.time_read
FROM history H FROM history H
JOIN chapters C JOIN chapters C
ON H.chapter_id = C._id ON H.chapter_id = C._id
WHERE C.url = :chapterUrl AND C._id = H.chapter_id; WHERE C.manga_id = :mangaId AND C.url = :chapterUrl AND C._id = H.chapter_id;
resetHistoryById: resetHistoryById:
UPDATE history UPDATE history