Improve history migration

This commit is contained in:
Jobobby04 2023-04-16 14:12:48 -04:00
parent 4212d155ce
commit b26749d61c
4 changed files with 25 additions and 3 deletions

View File

@ -344,9 +344,7 @@ class MigrationListScreenModel(
}
updateChapter.awaitAll(chapterUpdates)
historyUpdates.forEach {
upsertHistory.await(it)
}
upsertHistory.awaitAll(historyUpdates)
}
// Update categories
if (MigrationFlags.hasCategories(flags)) {

View File

@ -70,6 +70,22 @@ class HistoryRepositoryImpl(
}
// SY -->
override suspend fun upsertHistory(historyUpdates: List<HistoryUpdate>) {
try {
handler.await(true) {
historyUpdates.forEach { historyUpdate ->
historyQueries.upsert(
historyUpdate.chapterId,
historyUpdate.readAt,
historyUpdate.sessionReadDuration,
)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, throwable = e)
}
}
override suspend fun getByMangaId(mangaId: Long): List<History> {
return handler.awaitList { historyQueries.getHistoryByMangaId(mangaId, historyMapper) }
}

View File

@ -10,4 +10,10 @@ class UpsertHistory(
suspend fun await(historyUpdate: HistoryUpdate) {
historyRepository.upsertHistory(historyUpdate)
}
// SY -->
suspend fun awaitAll(historyUpdates: List<HistoryUpdate>) {
historyRepository.upsertHistory(historyUpdates)
}
// SY <--
}

View File

@ -22,6 +22,8 @@ interface HistoryRepository {
suspend fun upsertHistory(historyUpdate: HistoryUpdate)
// SY -->
suspend fun upsertHistory(historyUpdates: List<HistoryUpdate>)
suspend fun getByMangaId(mangaId: Long): List<History>
// SY <--
}