mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 02:20:24 +08:00
优化代码
This commit is contained in:
@@ -33,7 +33,7 @@ func TestDB_Instance(t *testing.T) {
|
|||||||
if err == driver.ErrBadConn {
|
if err == driver.ErrBadConn {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Fatal(i, "exec:", err)
|
t.Error(i, "exec:", err)
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
|
|||||||
|
|
||||||
// ExistDomainRecord 检查域名解析记录是否存在
|
// ExistDomainRecord 检查域名解析记录是否存在
|
||||||
func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) {
|
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{
|
query := maps.Map{
|
||||||
"name": recordName,
|
"name": recordName,
|
||||||
"type": recordType,
|
"type": recordType,
|
||||||
@@ -239,7 +241,6 @@ func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordNa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recordType = strings.ToUpper(recordType)
|
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(domainId).
|
Pk(domainId).
|
||||||
Where("JSON_CONTAINS(records, :query)").
|
Where("JSON_CONTAINS(records, :query)").
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ func TestServerClientBrowserMonthlyStatDAO_IncreaseMonthlyCount(t *testing.T) {
|
|||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
var tx *dbs.Tx
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func TestTrafficDailyStatDAO_IncreaseDayBytes(t *testing.T) {
|
|||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
|
|
||||||
now := time.Now()
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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("x-sdk-date", datetime)
|
||||||
req.Header.Set("Authorization", "SDK-HMAC-SHA256 Access="+this.accessKeyId+", SignedHeaders=content-type;host;x-sdk-date, Signature="+signString)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ func (this *NSNodeService) ListEnabledNSNodesMatch(ctx context.Context, req *pb.
|
|||||||
|
|
||||||
var tx = this.NullTx()
|
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)
|
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{}
|
pbNodes := []*pb.NSNode{}
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// 安装信息
|
// 安装信息
|
||||||
@@ -405,6 +408,9 @@ func (this *NSNodeService) DownloadNSNodeInstallationFile(ctx context.Context, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
data, offset, err := file.Read(req.ChunkOffset)
|
data, offset, err := file.Read(req.ChunkOffset)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &pb.DownloadNSNodeInstallationFileResponse{
|
return &pb.DownloadNSNodeInstallationFileResponse{
|
||||||
Sum: sum,
|
Sum: sum,
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ func (this *SQLDump) tryCreateIndex(err error, db *dbs.DB, tableName string, ind
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理Duplicate entry
|
// 处理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 // 尝试次数
|
var tries = 5 // 尝试次数
|
||||||
for i := 0; i < tries; i++ {
|
for i := 0; i < tries; i++ {
|
||||||
_, err = db.Exec("TRUNCATE TABLE " + tableName)
|
_, err = db.Exec("TRUNCATE TABLE " + tableName)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -279,7 +278,6 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemId int64 = 0
|
|
||||||
if len(itemMap) == 0 {
|
if len(itemMap) == 0 {
|
||||||
keysJSON, err := json.Marshal(keys)
|
keysJSON, err := json.Marshal(keys)
|
||||||
if err != nil {
|
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
|
// chart
|
||||||
for _, chartMap := range chartMaps {
|
for _, chartMap := range chartMaps {
|
||||||
@@ -461,17 +459,3 @@ func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error {
|
|||||||
|
|
||||||
return nil
|
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