mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-30 18:16:36 +08:00
优化代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -37,7 +38,7 @@ func (this *APINode) DecodeHTTPS(tx *dbs.Tx, cacheMap *utils.CacheMap) (*serverc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +56,7 @@ func (this *APINode) DecodeHTTPS(tx *dbs.Tx, cacheMap *utils.CacheMap) (*serverc
|
||||
}
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,7 +136,7 @@ func (this *APINode) DecodeRestHTTPS(tx *dbs.Tx, cacheMap *utils.CacheMap) (*ser
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -153,7 +154,7 @@ func (this *APINode) DecodeRestHTTPS(tx *dbs.Tx, cacheMap *utils.CacheMap) (*ser
|
||||
}
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ Loop:
|
||||
|
||||
// CreateHTTPAccessLog 写入单条访问日志
|
||||
func (this *HTTPAccessLogDAO) CreateHTTPAccessLog(tx *dbs.Tx, dao *HTTPAccessLogDAO, accessLog *pb.HTTPAccessLog) error {
|
||||
var day = ""
|
||||
var day string
|
||||
// 注意:如果你修改了 TimeISO8601 的逻辑,这里也需要同步修改
|
||||
if len(accessLog.TimeISO8601) > 10 {
|
||||
day = strings.ReplaceAll(accessLog.TimeISO8601[:10], "-", "")
|
||||
|
||||
@@ -373,7 +373,7 @@ func (this *HTTPAccessLogManager) findTableWithoutCache(db *dbs.DB, day string,
|
||||
var lastInt64Id = types.Int64(lastId)
|
||||
if accessLogRowsPerTable > 0 && lastInt64Id >= accessLogRowsPerTable {
|
||||
// create next partial table
|
||||
var nextTableName = ""
|
||||
var nextTableName string
|
||||
if accessLogTableMainReg.MatchString(lastTableName) {
|
||||
nextTableName = prefix + "_0001"
|
||||
} else if accessLogTablePartialReg.MatchString(lastTableName) {
|
||||
|
||||
@@ -674,6 +674,9 @@ func (this *IPItemDAO) NotifyUpdate(tx *dbs.Tx, itemId int64) error {
|
||||
}
|
||||
} else {
|
||||
clusterIds, err := SharedNodeClusterDAO.FindAllEnabledNodeClusterIds(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, clusterId := range clusterIds {
|
||||
err = SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleNode, clusterId, 0, 0, NodeTaskTypeIPItemChanged)
|
||||
if err != nil {
|
||||
|
||||
@@ -1039,9 +1039,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, dataMap *shared
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, clusterServer := range clusterServers {
|
||||
servers = append(servers, clusterServer)
|
||||
}
|
||||
servers = append(servers, clusterServers...)
|
||||
}
|
||||
|
||||
for _, server := range servers {
|
||||
@@ -1063,7 +1061,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, dataMap *shared
|
||||
// TODO 根据用户的不同读取不同的全局设置
|
||||
var settingCacheKey = "SharedSysSettingDAO:" + systemconfigs.SettingCodeServerGlobalConfig
|
||||
settingJSONCache, ok := cacheMap.Get(settingCacheKey)
|
||||
var settingJSON = []byte{}
|
||||
var settingJSON []byte
|
||||
if ok {
|
||||
settingJSON = settingJSONCache.([]byte)
|
||||
} else {
|
||||
@@ -2124,7 +2122,7 @@ func (this *NodeDAO) FindParentNodeConfigs(tx *dbs.Tx, nodeId int64, groupId int
|
||||
var secretHash = fmt.Sprintf("%x", sha256.Sum256([]byte(node.UniqueId+"@"+node.Secret)))
|
||||
|
||||
for _, clusterId := range node.AllClusterIds() {
|
||||
parentNodeConfigs, _ := result[clusterId]
|
||||
var parentNodeConfigs = result[clusterId]
|
||||
parentNodeConfigs = append(parentNodeConfigs, &nodeconfigs.ParentNodeConfig{
|
||||
Id: int64(node.Id),
|
||||
Addrs: addrStrings,
|
||||
|
||||
@@ -70,8 +70,7 @@ func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domainRoutes, _ := routes[dnsDomainId]
|
||||
|
||||
var domainRoutes = routes[dnsDomainId]
|
||||
if len(domainRoutes) > 0 {
|
||||
sort.Strings(domainRoutes)
|
||||
}
|
||||
|
||||
@@ -127,6 +127,9 @@ func (this *RegionCountryDAO) CreateCountry(tx *dbs.Tx, name string, dataId stri
|
||||
pinyinResult = append(pinyinResult, strings.Join(piece, " "))
|
||||
}
|
||||
pinyinJSON, err := json.Marshal([]string{strings.Join(pinyinResult, " ")})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
op.Pinyin = pinyinJSON
|
||||
|
||||
codes := []string{name}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -78,7 +79,7 @@ func (this *Server) DecodeHTTPSPorts() (ports []int) {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -120,7 +121,7 @@ func (this *Server) DecodeTLSPorts() (ports []int) {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -701,7 +701,7 @@ func (this *SSLCertDAO) buildDomainSearchingQuery(query *dbs.Query, domains []st
|
||||
}
|
||||
|
||||
// 检测 JSON_OVERLAPS() 函数是否可用
|
||||
var canJSONOverlaps = false
|
||||
var canJSONOverlaps bool
|
||||
_, funcErr := this.Instance.FindCol(0, "SELECT JSON_OVERLAPS('[1]', '[1]')")
|
||||
canJSONOverlaps = funcErr == nil
|
||||
if canJSONOverlaps {
|
||||
|
||||
@@ -522,16 +522,6 @@ func (this *UserBandwidthStatDAO) sumBytesField(useAvg bool) string {
|
||||
return "SUM(bytes) AS bytes"
|
||||
}
|
||||
|
||||
func (this *UserBandwidthStatDAO) fixUserStat(stat *UserBandwidthStat, useAvg bool) *UserBandwidthStat {
|
||||
if stat == nil {
|
||||
return nil
|
||||
}
|
||||
if useAvg {
|
||||
stat.Bytes = stat.AvgBytes
|
||||
}
|
||||
return stat
|
||||
}
|
||||
|
||||
// HasFullData 检查一个月是否完整数据
|
||||
// 是为了兼容以前数据,以前的表中没有缓存流量、请求数等字段
|
||||
func (this *UserBandwidthStatDAO) HasFullData(tx *dbs.Tx, userId int64, month string) (bool, error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -36,7 +37,7 @@ func (this *UserNode) DecodeHTTPS(cacheMap *utils.CacheMap) (*serverconfigs.HTTP
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -54,7 +55,7 @@ func (this *UserNode) DecodeHTTPS(cacheMap *utils.CacheMap) (*serverconfigs.HTTP
|
||||
}
|
||||
}
|
||||
|
||||
err = config.Init(nil)
|
||||
err = config.Init(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user