优化代码

This commit is contained in:
GoEdgeLab
2021-08-07 16:11:35 +08:00
parent 80a309fb9b
commit c0a67b1358
8 changed files with 14 additions and 23 deletions

View File

@@ -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)

View File

@@ -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
}