Attempt to fix crash when migrating or removing entries from library (mihonapp/mihon#1828)

Co-authored-by: Cuong-Tran <cuongtran.tm@gmail.com>
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
(cherry picked from commit 563bc02113a5ebc53650fdfdd13f408284a0cdc8)
This commit is contained in:
FlaminSarge 2025-03-06 01:51:09 -08:00 committed by Cuong-Tran
parent 870d77ed1f
commit 6e291c1510
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
4 changed files with 31 additions and 4 deletions

View file

@ -38,6 +38,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Fix backup/restore of category related preferences ([@cuong-tran](https://github.com/cuong-tran)) ([#1726](https://github.com/mihonapp/mihon/pull/1726)) - Fix backup/restore of category related preferences ([@cuong-tran](https://github.com/cuong-tran)) ([#1726](https://github.com/mihonapp/mihon/pull/1726))
- Fix WebView sending app's package name in `X-Requested-With` header, which led to sources blocking access ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#1812](https://github.com/mihonapp/mihon/pull/1812)) - Fix WebView sending app's package name in `X-Requested-With` header, which led to sources blocking access ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#1812](https://github.com/mihonapp/mihon/pull/1812))
- Fix an issue where tracker reading progress is changed to a lower value ([@Animeboynz](https://github.com/Animeboynz)) ([#1795](https://github.com/mihonapp/mihon/pull/1795)) - Fix an issue where tracker reading progress is changed to a lower value ([@Animeboynz](https://github.com/Animeboynz)) ([#1795](https://github.com/mihonapp/mihon/pull/1795))
- Attempt to fix crash when migrating or removing entries from library ([@FlaminSarge](https://github.com/FlaminSarge)) ([#1828](https://github.com/mihonapp/mihon/pull/1828))
### Removed ### Removed
- Remove alphabetical category sort option - Remove alphabetical category sort option

View file

@ -1,8 +1,14 @@
package tachiyomi.domain.manga.interactor package tachiyomi.domain.manga.interactor
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.retry
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.repository.MangaRepository import tachiyomi.domain.manga.repository.MangaRepository
import kotlin.time.Duration.Companion.seconds
class GetFavorites( class GetFavorites(
private val mangaRepository: MangaRepository, private val mangaRepository: MangaRepository,
@ -14,5 +20,17 @@ class GetFavorites(
fun subscribe(sourceId: Long): Flow<List<Manga>> { fun subscribe(sourceId: Long): Flow<List<Manga>> {
return mangaRepository.getFavoritesBySourceId(sourceId) return mangaRepository.getFavoritesBySourceId(sourceId)
// KMK -->
.retry {
if (it is NullPointerException) {
delay(0.5.seconds)
true
} else {
false
}
}.catch {
this@GetFavorites.logcat(LogPriority.ERROR, it)
}
// KMK <--
} }
} }

View file

@ -2,7 +2,10 @@ package tachiyomi.domain.manga.interactor
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.retry import kotlinx.coroutines.flow.retry
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.manga.repository.MangaRepository import tachiyomi.domain.manga.repository.MangaRepository
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
@ -17,15 +20,15 @@ class GetLibraryManga(
fun subscribe(): Flow<List<LibraryManga>> { fun subscribe(): Flow<List<LibraryManga>> {
return mangaRepository.getLibraryMangaAsFlow() return mangaRepository.getLibraryMangaAsFlow()
// SY -->
.retry { .retry {
if (it is NullPointerException) { if (it is NullPointerException) {
delay(5.seconds) delay(0.5.seconds)
true true
} else { } else {
false false
} }
}.catch {
this@GetLibraryManga.logcat(LogPriority.ERROR, it)
} }
// SY <--
} }
} }

View file

@ -2,9 +2,12 @@ package tachiyomi.domain.updates.interactor
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.retry import kotlinx.coroutines.flow.retry
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.updates.model.UpdatesWithRelations import tachiyomi.domain.updates.model.UpdatesWithRelations
import tachiyomi.domain.updates.repository.UpdatesRepository import tachiyomi.domain.updates.repository.UpdatesRepository
import java.time.Instant import java.time.Instant
@ -41,11 +44,13 @@ class GetUpdates(
// SY --> // SY -->
private fun <T> Flow<T>.catchNPE() = retry { private fun <T> Flow<T>.catchNPE() = retry {
if (it is NullPointerException) { if (it is NullPointerException) {
delay(5.seconds) delay(0.5.seconds)
true true
} else { } else {
false false
} }
}.catch {
this@GetUpdates.logcat(LogPriority.ERROR, it)
} }
// SY <-- // SY <--
} }