flatten the code

This commit is contained in:
Aria Moradi 2021-04-02 13:56:38 +04:30
parent 640ce8f5d7
commit 68e69085df

View File

@ -29,30 +29,32 @@ object Source {
fun getHttpSource(sourceId: Long): HttpSource {
val cachedResult: HttpSource? = sourceCache[sourceId]
if (cachedResult != null) {
logger.debug("used cached HttpSource: ${cachedResult.name}")
return cachedResult
}
transaction {
val sourceRecord = SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()!!
val sourceRecord = transaction {
SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()!!
}
val extensionId = sourceRecord[SourceTable.extension]
val extensionRecord = ExtensionTable.select { ExtensionTable.id eq extensionId }.firstOrNull()!!
val apkName = extensionRecord[ExtensionTable.apkName]
val className = extensionRecord[ExtensionTable.classFQName]
val jarName = apkName.substringBefore(".apk") + ".jar"
val jarPath = "${ApplicationDirs.extensionsRoot}/$jarName"
val extensionId = sourceRecord[SourceTable.extension]
val extensionRecord = transaction {
ExtensionTable.select { ExtensionTable.id eq extensionId }.firstOrNull()!!
}
val extensionInstance = loadExtensionInstance(jarPath, className)
val apkName = extensionRecord[ExtensionTable.apkName]
val className = extensionRecord[ExtensionTable.classFQName]
val jarName = apkName.substringBefore(".apk") + ".jar"
val jarPath = "${ApplicationDirs.extensionsRoot}/$jarName"
if (sourceRecord[SourceTable.partOfFactorySource]) {
(extensionInstance as SourceFactory).createSources().forEach {
sourceCache[it.id] = it as HttpSource
}
} else {
(extensionInstance as HttpSource).also {
sourceCache[it.id] = it
}
val extensionInstance = loadExtensionInstance(jarPath, className)
if (sourceRecord[SourceTable.partOfFactorySource]) {
(extensionInstance as SourceFactory).createSources().forEach {
sourceCache[it.id] = it as HttpSource
}
} else {
(extensionInstance as HttpSource).also {
sourceCache[it.id] = it
}
}
return sourceCache[sourceId]!!