Fix deadlocks in gallery adder, favorites sync and backup/restore

This commit is contained in:
NerdNumber9
2019-04-14 18:20:22 -04:00
parent 24e10d6037
commit 6951ce34c7
3 changed files with 29 additions and 22 deletions

View File

@@ -46,11 +46,13 @@ interface LewdSource<M : RaisedSearchMetadata, I> : CatalogueSource {
fun parseToManga(manga: SManga, input: I): Completable {
val mangaId = (manga as? Manga)?.id
val metaObservable = if(mangaId != null) {
db.getFlatMetadataForManga(mangaId).asRxSingle()
.map {
if(it != null) it.raise(metaClass)
else newMetaInstance()
}
// We have to use fromCallable because StorIO messes up the thread scheduling if we use their rx functions
Single.fromCallable {
db.getFlatMetadataForManga(mangaId).executeAsBlocking()
} .map {
if(it != null) it.raise(metaClass)
else newMetaInstance()
}
} else {
Single.just(newMetaInstance())
}
@@ -76,10 +78,12 @@ interface LewdSource<M : RaisedSearchMetadata, I> : CatalogueSource {
*/
fun getOrLoadMetadata(mangaId: Long?, inputProducer: () -> Single<I>): Single<M> {
val metaObservable = if(mangaId != null) {
db.getFlatMetadataForManga(mangaId).asRxSingle()
.map {
it?.raise(metaClass)
}
// We have to use fromCallable because StorIO messes up the thread scheduling if we use their rx functions
Single.fromCallable {
db.getFlatMetadataForManga(mangaId).executeAsBlocking()
}.map {
it?.raise(metaClass)
}
} else Single.just(null)
return metaObservable.flatMap { existingMeta ->