mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-04 16:18:55 +01:00
Make syncChaptersWithSource use sqldelight (#7263)
* Make `syncChaptersWithSource` use sqldelight Will break chapter list live update on current ui Co-Authored-By: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> * Review Changes Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package eu.kanade.data.chapter
|
||||
|
||||
import eu.kanade.data.DatabaseHandler
|
||||
import eu.kanade.data.toLong
|
||||
import eu.kanade.domain.chapter.model.Chapter
|
||||
import eu.kanade.domain.chapter.model.ChapterUpdate
|
||||
import eu.kanade.domain.chapter.repository.ChapterRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
@@ -11,6 +12,33 @@ class ChapterRepositoryImpl(
|
||||
private val handler: DatabaseHandler,
|
||||
) : ChapterRepository {
|
||||
|
||||
override suspend fun addAll(chapters: List<Chapter>): List<Chapter> {
|
||||
return try {
|
||||
handler.await(inTransaction = true) {
|
||||
chapters.map { chapter ->
|
||||
chaptersQueries.insert(
|
||||
chapter.mangaId,
|
||||
chapter.url,
|
||||
chapter.name,
|
||||
chapter.scanlator,
|
||||
chapter.read,
|
||||
chapter.bookmark,
|
||||
chapter.lastPageRead,
|
||||
chapter.chapterNumber,
|
||||
chapter.sourceOrder,
|
||||
chapter.dateFetch,
|
||||
chapter.dateUpload,
|
||||
)
|
||||
val lastInsertId = chaptersQueries.selectLastInsertedRowId().executeAsOne()
|
||||
chapter.copy(id = lastInsertId)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun update(chapterUpdate: ChapterUpdate) {
|
||||
try {
|
||||
handler.await {
|
||||
@@ -33,4 +61,46 @@ class ChapterRepositoryImpl(
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAll(chapterUpdates: List<ChapterUpdate>) {
|
||||
try {
|
||||
handler.await(inTransaction = true) {
|
||||
chapterUpdates.forEach { chapterUpdate ->
|
||||
chaptersQueries.update(
|
||||
chapterUpdate.mangaId,
|
||||
chapterUpdate.url,
|
||||
chapterUpdate.name,
|
||||
chapterUpdate.scanlator,
|
||||
chapterUpdate.read?.toLong(),
|
||||
chapterUpdate.bookmark?.toLong(),
|
||||
chapterUpdate.lastPageRead,
|
||||
chapterUpdate.chapterNumber?.toDouble(),
|
||||
chapterUpdate.sourceOrder,
|
||||
chapterUpdate.dateFetch,
|
||||
chapterUpdate.dateUpload,
|
||||
chapterId = chapterUpdate.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeChaptersWithIds(chapterIds: List<Long>) {
|
||||
try {
|
||||
handler.await { chaptersQueries.removeChaptersWithIds(chapterIds) }
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getChapterByMangaId(mangaId: Long): List<Chapter> {
|
||||
return try {
|
||||
handler.awaitList { chaptersQueries.getChapterByMangaId(mangaId, chapterMapper) }
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,12 @@ class MangaRepositoryImpl(
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateLastUpdate(mangaId: Long, lastUpdate: Long) {
|
||||
try {
|
||||
handler.await { mangasQueries.updateLastUpdate(lastUpdate, mangaId) }
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user