Skip to content

Commit

Permalink
feat: optimize configuration loading logic for enhanced efficiency an…
Browse files Browse the repository at this point in the history
…d reliability
  • Loading branch information
tangcent committed Mar 10, 2024
1 parent e1be9fe commit 455af89
Show file tree
Hide file tree
Showing 44 changed files with 538 additions and 626 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ plugin_version=2.6.8.212.0
kotlin.code.style=official
kotlin_version=1.8.0
junit_version=5.9.2
itangcent_intellij_version=1.6.2
itangcent_intellij_version=1.6.23-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.itangcent.idea.binder
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import com.itangcent.idea.sqlite.SqliteDataResourceHelper
import com.itangcent.idea.sqlite.delete
import com.itangcent.idea.sqlite.get
import com.itangcent.idea.sqlite.set
import com.itangcent.idea.utils.JacksonUtils
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.file.BeanBinder
Expand All @@ -16,40 +19,35 @@ class DbBeanBinderFactory<T : Any>(private val file: String, protected var init:
}

private var dbBeanBinderCache: Cache<String, BeanBinder<T>> = CacheBuilder.newBuilder()
.maximumSize(20)
.build()
.maximumSize(20)
.build()

fun getBeanBinder(beanBindName: String): BeanBinder<T> {
return dbBeanBinderCache.get(beanBindName) { DbBeanBinder(beanBindName) }
}

fun deleteBinder(beanBindName: String) {
dao.delete(beanBindName.toByteArray())
dao.delete(beanBindName)
}

inner class DbBeanBinder : BeanBinder<T> {
private val beanBindName: String

constructor(beanBindName: String) {
this.beanBindName = beanBindName
}
inner class DbBeanBinder(private val beanBindName: String) : BeanBinder<T> {

override fun tryRead(): T? {
return dao.get(beanBindName.toByteArray())
?.let { JacksonUtils.fromJson<T>(String(it)) }
return dao.get(beanBindName)
?.let { JacksonUtils.fromJson<T>(it) }
}

override fun read(): T {
return dao.get(beanBindName.toByteArray())
?.let { JacksonUtils.fromJson<T>(String(it)) }
?: return init()
return dao.get(beanBindName)
?.let { JacksonUtils.fromJson<T>(it) }
?: return init()
}

override fun save(t: T?) {
if (t == null) {
dao.delete(beanBindName.toByteArray())
dao.delete(beanBindName)
} else {
dao.set(beanBindName.toByteArray(), JacksonUtils.toJson(t).toByteArray())
dao.set(beanBindName, JacksonUtils.toJson(t))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import com.itangcent.idea.plugin.api.call.ApiCaller
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter
import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -34,9 +31,6 @@ class ApiCallAction : ApiExportAction("Call Api") {

builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }

builder.bind(ApiCaller::class) { it.singleton() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import com.itangcent.idea.plugin.api.cache.CachedRequestClassExporter
import com.itangcent.idea.plugin.api.dashboard.ApiDashBoard
import com.itangcent.idea.plugin.api.export.ExportChannel
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter
import com.itangcent.idea.plugin.api.export.core.CompositeRequestBuilderListener
import com.itangcent.idea.plugin.api.export.core.RequestBuilderListener
import com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper
import com.itangcent.idea.plugin.api.export.postman.PostmanCachedApiHelper
import com.itangcent.idea.plugin.api.export.postman.PostmanConfigReader
import com.itangcent.idea.plugin.api.export.postman.PostmanRequestBuilderListener
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.idea.swing.ActiveWindowProvider
import com.itangcent.idea.swing.SimpleActiveWindowProvider
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -37,11 +36,8 @@ class ApiDashBoardAction : ApiExportAction("ApiDashBoard") {

builder.bindInstance(ExportChannel::class, ExportChannel.of("postman"))
builder.bindInstance(ExportDoc::class, ExportDoc.of("request"))

builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(PostmanConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }
builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }
builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }

builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import com.itangcent.idea.plugin.api.cache.FileApiCacheRepository
import com.itangcent.idea.plugin.api.cache.ProjectCacheRepository
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.spring.SpringRequestClassExporter
import com.itangcent.idea.plugin.config.EnhancedConfigReader
import com.itangcent.idea.plugin.rule.SuvRuleParser
import com.itangcent.idea.utils.CustomizedPsiClassHelper
import com.itangcent.idea.utils.RuleComputeListenerRegistry
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.config.rule.RuleComputeListener
import com.itangcent.intellij.config.rule.RuleParser
import com.itangcent.intellij.context.ActionContext
Expand All @@ -18,7 +20,6 @@ import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
import com.itangcent.intellij.file.LocalFileRepository
import com.itangcent.intellij.jvm.PsiClassHelper
import com.itangcent.intellij.util.ActionUtils

abstract class ApiExportAction(text: String) : BasicAnAction(text) {

Expand All @@ -35,6 +36,8 @@ abstract class ApiExportAction(text: String) : BasicAnAction(text) {
builder.bind(LocalFileRepository::class, "projectCacheRepository") {
it.with(ProjectCacheRepository::class).singleton()
}

builder.bind(ConfigReader::class) { it.with(EnhancedConfigReader::class).singleton() }
}

override fun actionPerformed(actionContext: ActionContext, project: Project?, anActionEvent: AnActionEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiType
import com.itangcent.common.logger.traceError
import com.itangcent.idea.plugin.api.cache.ProjectCacheRepository
import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.idea.plugin.format.MessageFormatter
import com.itangcent.idea.plugin.rule.SuvRuleParser
import com.itangcent.idea.utils.CustomizedPsiClassHelper
import com.itangcent.idea.utils.RuleComputeListenerRegistry
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.config.rule.RuleComputeListener
import com.itangcent.intellij.config.rule.RuleParser
import com.itangcent.intellij.context.ActionContext
Expand Down Expand Up @@ -58,9 +54,6 @@ abstract class FieldsToMessageAction : BasicAnAction {
it.with(ProjectCacheRepository::class).singleton()
}

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bind(RuleComputeListener::class) { it.with(RuleComputeListenerRegistry::class).singleton() }
builder.bind(PsiClassHelper::class) { it.with(CustomizedPsiClassHelper::class).singleton() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.itangcent.idea.plugin.api.export.ExportChannel
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.condition.ConditionOnSimple
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.generic.GenericMethodDocClassExporter
import com.itangcent.idea.plugin.api.export.generic.GenericRequestClassExporter
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter
import com.itangcent.idea.plugin.api.export.core.ConfigurableMethodFilter
import com.itangcent.idea.plugin.api.export.core.MethodFilter
import com.itangcent.idea.plugin.api.export.markdown.MarkdownApiExporter
import com.itangcent.idea.plugin.api.export.spring.SpringRequestClassExporter
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -24,10 +21,6 @@ class MarkdownExportAction : ApiExportAction("Export Markdown") {
super.afterBuildActionContext(event, builder)

builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bind(ClassExporter::class) { it.with(CompositeClassExporter::class).singleton() }

builder.bindInstance(ExportChannel::class, ExportChannel.of("markdown"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import com.intellij.openapi.project.Project
import com.itangcent.idea.plugin.api.export.ExportChannel
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.postman.*
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.idea.plugin.api.export.postman.PostmanApiExporter
import com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper
import com.itangcent.idea.plugin.api.export.postman.PostmanCachedApiHelper
import com.itangcent.idea.plugin.api.export.postman.PostmanFormatFolderHelper
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -27,10 +28,6 @@ class PostmanExportAction : ApiExportAction("Export Postman") {

builder.bind(PostmanApiHelper::class) { it.with(PostmanCachedApiHelper::class).singleton() }
builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(PostmanConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bind(ClassExporter::class) { it.with(CompositeClassExporter::class).singleton() }

builder.bindInstance(ExportChannel::class, ExportChannel.of("postman"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import com.intellij.openapi.project.Project
import com.itangcent.idea.plugin.api.cache.CachedRequestClassExporter
import com.itangcent.idea.plugin.api.debug.ScriptExecutor
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.core.EasyApiConfigReader
import com.itangcent.idea.plugin.api.export.spring.SpringRequestClassExporter
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -23,12 +20,10 @@ class ScriptExecutorAction : ApiExportAction("ScriptExecutor") {
builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }

//allow cache api
builder.bind(ClassExporter::class, "delegate_classExporter") { it.with(SpringRequestClassExporter::class).singleton() }
builder.bind(ClassExporter::class, "delegate_classExporter") {
it.with(SpringRequestClassExporter::class).singleton()
}
builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bindInstance("file.save.default", "script.txt")
builder.bindInstance("file.save.last.location.key", "com.itangcent.debug.loadOrSave.path")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import com.intellij.openapi.project.Project
import com.itangcent.idea.plugin.DataEventCollector
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.condition.markAsSimple
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.core.ClassExporter
import com.itangcent.idea.plugin.api.export.core.CompositeClassExporter
import com.itangcent.idea.plugin.api.export.core.ConfigurableMethodFilter
import com.itangcent.idea.plugin.api.export.core.MethodFilter
import com.itangcent.idea.plugin.api.export.postman.PostmanApiHelper
import com.itangcent.idea.plugin.api.export.postman.PostmanCachedApiHelper
import com.itangcent.idea.plugin.api.export.suv.SuvApiExporter
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand Down Expand Up @@ -47,9 +48,6 @@ class SuvExportAction : ApiExportAction("Export Api") {

builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(EasyApiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }

builder.bind(SuvApiExporter::class) { it.singleton() }

builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import com.itangcent.idea.plugin.api.export.ExportChannel
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.yapi.*
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.idea.swing.ActiveWindowProvider
import com.itangcent.idea.swing.SimpleActiveWindowProvider
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -27,9 +25,6 @@ class YapiDashBoardAction : ApiExportAction("YapiDashBoard") {

builder.bind(LocalFileRepository::class) { it.with(DefaultLocalFileRepository::class).singleton() }
builder.bind(LinkResolver::class) { it.with(YapiLinkResolver::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(YapiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }
builder.bind(YapiDashBoard::class) { it.singleton() }

builder.bind(YapiApiDashBoardExporter::class) { it.singleton() }
Expand All @@ -43,7 +38,7 @@ class YapiDashBoardAction : ApiExportAction("YapiDashBoard") {

builder.bindInstance(ExportChannel::class, ExportChannel.of("yapi"))
builder.bindInstance(ExportDoc::class, ExportDoc.of("request", "methodDoc"))

builder.bind(ClassExporter::class) { it.with(CachedRequestClassExporter::class).singleton() }

builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import com.itangcent.idea.plugin.api.export.ExportChannel
import com.itangcent.idea.plugin.api.export.ExportDoc
import com.itangcent.idea.plugin.api.export.core.*
import com.itangcent.idea.plugin.api.export.yapi.*
import com.itangcent.idea.plugin.config.RecommendConfigReader
import com.itangcent.idea.plugin.settings.helper.YapiTokenChecker
import com.itangcent.intellij.config.ConfigReader
import com.itangcent.intellij.context.ActionContext
import com.itangcent.intellij.extend.guice.singleton
import com.itangcent.intellij.extend.guice.with
Expand All @@ -28,15 +26,13 @@ class YapiExportAction : ApiExportAction("Export Yapi") {
builder.bind(HttpClientProvider::class) { it.with(ConfigurableHttpClientProvider::class).singleton() }
builder.bind(LinkResolver::class) { it.with(YapiLinkResolver::class).singleton() }

builder.bind(ConfigReader::class, "delegate_config_reader") { it.with(YapiConfigReader::class).singleton() }
builder.bind(ConfigReader::class) { it.with(RecommendConfigReader::class).singleton() }
builder.bind(YapiApiHelper::class) { it.with(YapiCachedApiHelper::class).singleton() }

builder.bind(ClassExporter::class) { it.with(CompositeClassExporter::class).singleton() }

builder.bindInstance(ExportChannel::class, ExportChannel.of("yapi"))
builder.bindInstance(ExportDoc::class, ExportDoc.of("request", "methodDoc"))

builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
builder.bind(MethodDocBuilderListener::class) { it.with(CompositeMethodDocBuilderListener::class).singleton() }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.itangcent.idea.plugin.api.export.core

import com.itangcent.intellij.config.LocalFileSearchConfigProvider
import com.itangcent.order.Order
import com.itangcent.order.Ordered

@Order(Ordered.HIGHEST_PRECEDENCE)
class EasyApiConfigProvider : LocalFileSearchConfigProvider() {

override fun configFileNames(): List<String> {
return listOf(
".easy.api.config",
".easy.api.yml",
".easy.api.yaml"
)
}
}

This file was deleted.

Loading

0 comments on commit 455af89

Please sign in to comment.