Improve source handling, fix errors with uninitialized mangas in broken sources (#319)

This commit is contained in:
Mitchell Syer
2022-03-22 07:21:07 -04:00
committed by GitHub
parent a27af0b642
commit 152b193ad5
6 changed files with 59 additions and 56 deletions

View File

@@ -26,7 +26,7 @@ object GetCatalogueSource {
private val sourceCache = ConcurrentHashMap<Long, CatalogueSource>()
private val applicationDirs by DI.global.instance<ApplicationDirs>()
fun getCatalogueSource(sourceId: Long): CatalogueSource? {
private fun getCatalogueSource(sourceId: Long): CatalogueSource? {
val cachedResult: CatalogueSource? = sourceCache[sourceId]
if (cachedResult != null) {
return cachedResult
@@ -56,8 +56,12 @@ object GetCatalogueSource {
return sourceCache[sourceId]!!
}
fun getCatalogueSourceOrNull(sourceId: Long): CatalogueSource? {
return runCatching { getCatalogueSource(sourceId) }.getOrNull()
}
fun getCatalogueSourceOrStub(sourceId: Long): CatalogueSource {
return runCatching { getCatalogueSource(sourceId) }.getOrNull() ?: StubSource(sourceId)
return getCatalogueSourceOrNull(sourceId) ?: StubSource(sourceId)
}
fun registerCatalogueSource(sourcePair: Pair<Long, CatalogueSource>) {