clean un-relevant errors from DB on every updates

This commit is contained in:
Cuong-Tran 2024-10-24 14:00:27 +07:00
parent ff25910820
commit 5d95c72e03
No known key found for this signature in database
GPG Key ID: 733AA7624B9315C2
6 changed files with 32 additions and 3 deletions

View File

@ -110,6 +110,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
}
}
deleteLibraryUpdateErrors.cleanUnrelevantMangaErrors()
setForegroundSafely()
libraryPreferences.lastUpdatedTimestamp().set(Instant.now().toEpochMilli())

View File

@ -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(

View File

@ -30,3 +30,12 @@ WHERE _id = :_id;
deleteMangaError:
DELETE FROM libraryUpdateError
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
);

View File

@ -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()
}
}

View File

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

View File

@ -21,7 +21,7 @@ class DeleteLibraryUpdateErrorMessages(
}
sealed class Result {
object Success : Result()
data object Success : Result()
data class InternalError(val error: Throwable) : Result()
}
}