From aae455cee49fdfb3d61d1388f7d286ae83dd6ee1 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 10 十一月 2023 14:20:49 +0800
Subject: [PATCH] 引入pprof分析性能
---
serf/sqlite.go | 66 ++------------------------------
1 files changed, 5 insertions(+), 61 deletions(-)
diff --git a/serf/sqlite.go b/serf/sqlite.go
index 6ab2f6c..a617e1d 100644
--- a/serf/sqlite.go
+++ b/serf/sqlite.go
@@ -1,10 +1,8 @@
package serf
import (
- "apsClient/pkg/logx"
"errors"
"fmt"
- "regexp"
"strings"
"github.com/jinzhu/gorm"
@@ -50,13 +48,16 @@
}
var columnNames []string
+ var columnValues []string
for _, col := range tDescArr {
- columnNames = append(columnNames, fmt.Sprintf(`'||quote("%s")||'`, col.Name))
+ columnNames = append(columnNames, col.Name)
+ columnValues = append(columnValues, fmt.Sprintf(`'||quote("%s")||'`, col.Name))
}
- tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s";`,
+ tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" (%s) VALUES(%s)' as sql FROM "%s";`,
table,
strings.Join(columnNames, ","),
+ strings.Join(columnValues, ","),
table)
//fmt.Println("tSql:", tSql)
@@ -76,61 +77,4 @@
}
return nil, errors.New("tableNames is nil")
-}
-
-type DbLogger struct {
-}
-
-func (dbLogger *DbLogger) Print(values ...interface{}) {
- var (
- level = values[0]
- )
-
- fmt.Println("dblogger", values)
-
- if level == "sql" {
- msgArr := gorm.LogFormatter(values...)
- sql := msgArr[3].(string)
- logx.Infof("sql: %v", sql)
- sql = strings.TrimPrefix(sql, " ")
- if !strings.HasPrefix(sql, "SELECT") && !strings.HasPrefix(sql, "select") && !strings.Contains(sql, "PRAGMA") && !strings.Contains(sql, "pragma") {
- affected := values[5].(int64)
- if affected > 0 { //鎵ц鎴愬姛
- //鍒ゆ柇鎿嶄綔鐨勬槸鍝紶琛�
- whereIdx := strings.Index(sql, "WHERE")
- sqlWithTable := sql
- if whereIdx > -1 {
- sqlWithTable = sql[:whereIdx]
- }
-
- fmt.Println("鍒ゆ柇鏄摢寮犺〃 sqlWithTable:", sqlWithTable)
-
- insertReg := regexp.MustCompile(`^\s*(?i:insert)\s`) //insert
- updateReg := regexp.MustCompile(`^\s*(?i:update)\s`) //update
- delReg := regexp.MustCompile(`^\s*(?i:delete)\s`) //delete
-
- if insertReg.MatchString(sqlWithTable) {
- fmt.Println("鎻掑叆鎿嶄綔")
- for _, t := range agent.syncTables {
- reg := regexp.MustCompile(`\s+\"?(?i:` + t + `)\"?\s+`)
- if reg.MatchString(sqlWithTable) {
- fmt.Println("灞炰簬鍚屾琛�:", t)
- syncSqlChan <- sql
- }
- }
- } else if updateReg.MatchString(sqlWithTable) || delReg.MatchString(sqlWithTable) {
- fmt.Println("鍒犻櫎鎴栬�呮洿鏂�")
- for _, t := range agent.syncTables {
- reg := regexp.MustCompile(`\s+\"?(?i:` + t + `)\"?\s+`)
- if reg.MatchString(sqlWithTable) {
- fmt.Println("灞炰簬鍚屾琛�:", t)
- syncSqlChan <- sql
- }
- }
- }
- }
- }
- } else {
- fmt.Println("dbLogger level!=sql")
- }
}
--
Gitblit v1.8.0