diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index bd27935d1..0fdff72f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -110,6 +110,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet } } + deleteLibraryUpdateErrors.cleanUnrelevantMangaErrors() + setForegroundSafely() libraryPreferences.lastUpdatedTimestamp().set(Instant.now().toEpochMilli()) diff --git a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt index 061d18103..7fb014f7a 100644 --- a/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/libraryUpdateError/LibraryUpdateErrorRepositoryImpl.kt @@ -45,6 +45,12 @@ class LibraryUpdateErrorRepositoryImpl( } } + override suspend fun cleanUnrelevantMangaErrors() { + return handler.await { + libraryUpdateErrorQueries.cleanUnrelevantMangaErrors() + } + } + override suspend fun upsert(libraryUpdateError: LibraryUpdateError) { return handler.await(inTransaction = true) { libraryUpdateErrorQueries.upsert( diff --git a/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq b/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq index e268b38c4..e5a537910 100644 --- a/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq +++ b/data/src/main/sqldelight/tachiyomi/data/libraryUpdateError.sq @@ -29,4 +29,13 @@ WHERE _id = :_id; deleteMangaError: DELETE FROM libraryUpdateError -WHERE manga_id = :mangaId; \ No newline at end of file +WHERE manga_id = :mangaId; + +cleanUnrelevantMangaErrors: +DELETE FROM libraryUpdateError +WHERE NOT EXISTS ( + SELECT 1 + FROM mangas + WHERE libraryUpdateError.manga_id = mangas._id + AND mangas.favorite == 1 +); \ No newline at end of file diff --git a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/interactor/DeleteLibraryUpdateErrors.kt b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/interactor/DeleteLibraryUpdateErrors.kt index db637c2ce..f53158344 100644 --- a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/interactor/DeleteLibraryUpdateErrors.kt +++ b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/interactor/DeleteLibraryUpdateErrors.kt @@ -39,8 +39,18 @@ class DeleteLibraryUpdateErrors( } } + suspend fun cleanUnrelevantMangaErrors() = withNonCancellableContext { + try { + libraryUpdateErrorRepository.cleanUnrelevantMangaErrors() + Result.Success + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) + return@withNonCancellableContext Result.InternalError(e) + } + } + sealed class Result { - object Success : Result() + data object Success : Result() data class InternalError(val error: Throwable) : Result() } } diff --git a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/repository/LibraryUpdateErrorRepository.kt b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/repository/LibraryUpdateErrorRepository.kt index 044e97203..b5a5889ce 100644 --- a/domain/src/main/java/tachiyomi/domain/libraryUpdateError/repository/LibraryUpdateErrorRepository.kt +++ b/domain/src/main/java/tachiyomi/domain/libraryUpdateError/repository/LibraryUpdateErrorRepository.kt @@ -15,6 +15,8 @@ interface LibraryUpdateErrorRepository { suspend fun deleteMangaError(mangaId: Long) + suspend fun cleanUnrelevantMangaErrors() + suspend fun upsert(libraryUpdateError: LibraryUpdateError) suspend fun insert(libraryUpdateError: LibraryUpdateError) diff --git a/domain/src/main/java/tachiyomi/domain/libraryUpdateErrorMessage/interactor/DeleteLibraryUpdateErrorMessages.kt b/domain/src/main/java/tachiyomi/domain/libraryUpdateErrorMessage/interactor/DeleteLibraryUpdateErrorMessages.kt index 053c9b90f..a790c5053 100644 --- a/domain/src/main/java/tachiyomi/domain/libraryUpdateErrorMessage/interactor/DeleteLibraryUpdateErrorMessages.kt +++ b/domain/src/main/java/tachiyomi/domain/libraryUpdateErrorMessage/interactor/DeleteLibraryUpdateErrorMessages.kt @@ -21,7 +21,7 @@ class DeleteLibraryUpdateErrorMessages( } sealed class Result { - object Success : Result() + data object Success : Result() data class InternalError(val error: Throwable) : Result() } }