delete error from DB when successfully updated

This commit is contained in:
Cuong-Tran 2024-10-24 13:38:23 +07:00
parent 28fa0dec6a
commit ff25910820
No known key found for this signature in database
GPG Key ID: 733AA7624B9315C2
5 changed files with 32 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_HAS_U
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_READ
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_OUTSIDE_RELEASE_PERIOD
import tachiyomi.domain.libraryUpdateError.interactor.DeleteLibraryUpdateErrors
import tachiyomi.domain.libraryUpdateError.interactor.InsertLibraryUpdateErrors
import tachiyomi.domain.libraryUpdateError.model.LibraryUpdateError
import tachiyomi.domain.libraryUpdateErrorMessage.interactor.InsertLibraryUpdateErrorMessages
@ -87,6 +88,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
private val fetchInterval: FetchInterval = Injekt.get()
private val filterChaptersForDownload: FilterChaptersForDownload = Injekt.get()
private val deleteLibraryUpdateErrors: DeleteLibraryUpdateErrors = Injekt.get()
private val insertLibraryUpdateErrors: InsertLibraryUpdateErrors = Injekt.get()
private val insertLibraryUpdateErrorMessages: InsertLibraryUpdateErrorMessages = Injekt.get()
@ -283,6 +285,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
// Convert to the manga that contains new chapters
newUpdates.add(manga to newChapters.toTypedArray())
}
clearErrorFromDB(mangaId = manga.id)
} catch (e: Throwable) {
val errorMessage = when (e) {
is NoChaptersException -> context.stringResource(
@ -379,6 +382,10 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
)
}
private suspend fun clearErrorFromDB(mangaId: Long) {
deleteLibraryUpdateErrors.deleteMangaError(mangaId = mangaId)
}
private suspend fun writeErrorToDB(error: Pair<Manga, String?>) {
val errorMessage = error.second ?: "???"
val errorMessageId = insertLibraryUpdateErrorMessages.get(errorMessage)

View File

@ -37,6 +37,14 @@ class LibraryUpdateErrorRepositoryImpl(
}
}
override suspend fun deleteMangaError(mangaId: Long) {
return handler.await {
libraryUpdateErrorQueries.deleteMangaError(
mangaId = mangaId,
)
}
}
override suspend fun upsert(libraryUpdateError: LibraryUpdateError) {
return handler.await(inTransaction = true) {
libraryUpdateErrorQueries.upsert(

View File

@ -26,3 +26,7 @@ DELETE FROM libraryUpdateError;
deleteError:
DELETE FROM libraryUpdateError
WHERE _id = :_id;
deleteMangaError:
DELETE FROM libraryUpdateError
WHERE manga_id = :mangaId;

View File

@ -29,6 +29,16 @@ class DeleteLibraryUpdateErrors(
}
}
suspend fun deleteMangaError(mangaId: Long) = withNonCancellableContext {
try {
libraryUpdateErrorRepository.deleteMangaError(mangaId)
Result.Success
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
return@withNonCancellableContext Result.InternalError(e)
}
}
sealed class Result {
object Success : Result()
data class InternalError(val error: Throwable) : Result()

View File

@ -13,6 +13,8 @@ interface LibraryUpdateErrorRepository {
suspend fun delete(errorId: Long)
suspend fun deleteMangaError(mangaId: Long)
suspend fun upsert(libraryUpdateError: LibraryUpdateError)
suspend fun insert(libraryUpdateError: LibraryUpdateError)