mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +08:00
优化代码
This commit is contained in:
@@ -33,7 +33,7 @@ func TestDB_Instance(t *testing.T) {
|
||||
if err == driver.ErrBadConn {
|
||||
return
|
||||
}
|
||||
t.Fatal(i, "exec:", err)
|
||||
t.Error(i, "exec:", err)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
||||
@@ -218,6 +218,8 @@ func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
|
||||
|
||||
// ExistDomainRecord 检查域名解析记录是否存在
|
||||
func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) {
|
||||
recordType = strings.ToUpper(recordType)
|
||||
|
||||
query := maps.Map{
|
||||
"name": recordName,
|
||||
"type": recordType,
|
||||
@@ -239,7 +241,6 @@ func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordNa
|
||||
}
|
||||
}
|
||||
}
|
||||
recordType = strings.ToUpper(recordType)
|
||||
return this.Query(tx).
|
||||
Pk(domainId).
|
||||
Where("JSON_CONTAINS(records, :query)").
|
||||
|
||||
@@ -11,7 +11,7 @@ func TestServerClientBrowserMonthlyStatDAO_IncreaseMonthlyCount(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
var tx *dbs.Tx
|
||||
err := SharedServerClientBrowserMonthlyStatDAO.IncreaseMonthlyCount(tx, 1, 1, "202101", 1)
|
||||
err := SharedServerClientBrowserMonthlyStatDAO.IncreaseMonthlyCount(tx, 1, 1, "1.0", "202101", 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ func TestTrafficDailyStatDAO_IncreaseDayBytes(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
now := time.Now()
|
||||
err := SharedTrafficDailyStatDAO.IncreaseDailyBytes(nil, timeutil.Format("Ymd"), 1)
|
||||
err := SharedTrafficDailyStatDAO.IncreaseDailyStat(nil, timeutil.Format("Ymd"), 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1453,7 +1453,7 @@ func (this *HuaweiDNSProvider) doAPI(method string, apiPath string, args map[str
|
||||
req.Header.Set("x-sdk-date", datetime)
|
||||
req.Header.Set("Authorization", "SDK-HMAC-SHA256 Access="+this.accessKeyId+", SignedHeaders=content-type;host;x-sdk-date, Signature="+signString)
|
||||
|
||||
resp, err := cloudFlareHTTPClient.Do(req)
|
||||
resp, err := huaweiDNSHTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -91,6 +91,9 @@ func (this *NSNodeService) ListEnabledNSNodesMatch(ctx context.Context, req *pb.
|
||||
|
||||
var tx = this.NullTx()
|
||||
nodes, err := nameservers.SharedNSNodeDAO.ListAllEnabledNodesMatch(tx, req.NsClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbNodes := []*pb.NSNode{}
|
||||
for _, node := range nodes {
|
||||
// 安装信息
|
||||
@@ -405,6 +408,9 @@ func (this *NSNodeService) DownloadNSNodeInstallationFile(ctx context.Context, r
|
||||
}
|
||||
|
||||
data, offset, err := file.Read(req.ChunkOffset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DownloadNSNodeInstallationFileResponse{
|
||||
Sum: sum,
|
||||
|
||||
@@ -305,7 +305,7 @@ func (this *SQLDump) tryCreateIndex(err error, db *dbs.DB, tableName string, ind
|
||||
}
|
||||
|
||||
// 处理Duplicate entry
|
||||
if strings.Index(err.Error(), "Error 1062: Duplicate entry") >= 0 && (strings.HasSuffix(tableName, "Stats") || strings.HasSuffix(tableName, "Values")) {
|
||||
if strings.Contains(err.Error(), "Error 1062: Duplicate entry") && (strings.HasSuffix(tableName, "Stats") || strings.HasSuffix(tableName, "Values")) {
|
||||
var tries = 5 // 尝试次数
|
||||
for i := 0; i < tries; i++ {
|
||||
_, err = db.Exec("TRUNCATE TABLE " + tableName)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/iwind/TeaGo/types"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -279,7 +278,6 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var itemId int64 = 0
|
||||
if len(itemMap) == 0 {
|
||||
keysJSON, err := json.Marshal(keys)
|
||||
if err != nil {
|
||||
@@ -297,7 +295,7 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error {
|
||||
}
|
||||
}
|
||||
|
||||
itemId = itemMap.GetInt64("id")
|
||||
var itemId = itemMap.GetInt64("id")
|
||||
|
||||
// chart
|
||||
for _, chartMap := range chartMaps {
|
||||
@@ -461,17 +459,3 @@ func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断某个错误是否可以忽略
|
||||
func (this *SQLExecutor) canIgnoreError(err error) bool {
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// Error 1050: Table 'xxx' already exists
|
||||
if strings.Contains(err.Error(), "Error 1050") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user