diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Source.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Source.kt index ba8d3f4..cc8e1cc 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Source.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Source.kt @@ -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]!!