mirror of
https://github.com/mihonapp/mihon.git
synced 2025-01-30 11:54:54 +01:00
clean un-relevant errors from DB on every updates
This commit is contained in:
parent
ff25910820
commit
5d95c72e03
@ -110,6 +110,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
||||
}
|
||||
}
|
||||
|
||||
deleteLibraryUpdateErrors.cleanUnrelevantMangaErrors()
|
||||
|
||||
setForegroundSafely()
|
||||
|
||||
libraryPreferences.lastUpdatedTimestamp().set(Instant.now().toEpochMilli())
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
);
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ interface LibraryUpdateErrorRepository {
|
||||
|
||||
suspend fun deleteMangaError(mangaId: Long)
|
||||
|
||||
suspend fun cleanUnrelevantMangaErrors()
|
||||
|
||||
suspend fun upsert(libraryUpdateError: LibraryUpdateError)
|
||||
|
||||
suspend fun insert(libraryUpdateError: LibraryUpdateError)
|
||||
|
@ -21,7 +21,7 @@ class DeleteLibraryUpdateErrorMessages(
|
||||
}
|
||||
|
||||
sealed class Result {
|
||||
object Success : Result()
|
||||
data object Success : Result()
|
||||
data class InternalError(val error: Throwable) : Result()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user