优化节点配置生成速度

This commit is contained in:
GoEdgeLab
2021-11-11 14:16:42 +08:00
parent d18bddddd0
commit 212cf5b112
49 changed files with 527 additions and 198 deletions

View File

@@ -3,6 +3,7 @@ package models
import (
"encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
_ "github.com/go-sql-driver/mysql"
@@ -80,12 +81,12 @@ func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*Rev
}
// ComposeReverseProxyConfig 根据ID组合配置
func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyId int64, cacheMap maps.Map) (*serverconfigs.ReverseProxyConfig, error) {
func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyId int64, cacheMap *utils.CacheMap) (*serverconfigs.ReverseProxyConfig, error) {
if cacheMap == nil {
cacheMap = maps.Map{}
cacheMap = utils.NewCacheMap()
}
var cacheKey = this.Table + ":config:" + types.String(reverseProxyId)
var cache = cacheMap.Get(cacheKey)
var cache, _ = cacheMap.Get(cacheKey)
if cache != nil {
return cache.(*serverconfigs.ReverseProxyConfig), nil
}
@@ -200,7 +201,9 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
config.ProxyProtocol = proxyProtocolConfig
}
cacheMap[cacheKey] = config
if cacheMap != nil {
cacheMap.Put(cacheKey, config)
}
return config, nil
}