Fix crash when manually refresh repo db

This commit is contained in:
topjohnwu 2020-01-14 22:03:29 +08:00
parent 47c3045980
commit de853a2651

View File

@ -39,7 +39,7 @@ class RepoUpdater(
it.error()?.also { throw it } it.error()?.also { throw it }
it.response()?.run { it.response()?.run {
if (code() == HttpURLConnection.HTTP_NOT_MODIFIED) if (code() == HttpURLConnection.HTTP_NOT_MODIFIED)
return@run Flowable.error<Unit>(CachedException) return@run Flowable.error<Unit>(CachedException())
if (page == 1) if (page == 1)
repoDB.etagKey = headers()[Const.Key.ETAG_KEY].orEmpty().trimEtag() repoDB.etagKey = headers()[Const.Key.ETAG_KEY].orEmpty().trimEtag()
@ -64,8 +64,9 @@ class RepoUpdater(
@Suppress("RedundantLambdaArrow") @Suppress("RedundantLambdaArrow")
operator fun invoke(forced: Boolean = false) : Completable { operator fun invoke(forced: Boolean = false) : Completable {
val cached = Collections.synchronizedSet(HashSet(repoDB.repoIDList)) return Flowable.fromCallable { Collections.synchronizedSet(HashSet(repoDB.repoIDList)) }
return loadPage(cached, etag = repoDB.etagKey).doOnComplete { .flatMap { cached ->
loadPage(cached, etag = repoDB.etagKey).doOnComplete {
repoDB.removeRepos(cached) repoDB.removeRepos(cached)
}.onErrorResumeNext { it: Throwable -> }.onErrorResumeNext { it: Throwable ->
if (it is CachedException) { if (it is CachedException) {
@ -75,10 +76,11 @@ class RepoUpdater(
Timber.e(it) Timber.e(it)
} }
Flowable.empty() Flowable.empty()
}
}.ignoreElements() }.ignoreElements()
} }
object CachedException : Exception() class CachedException : Exception()
} }
private val dateFormat: SimpleDateFormat = private val dateFormat: SimpleDateFormat =