From 7ae1a3486ad0bdd545e05f10bc3af1d7d74a99fb Mon Sep 17 00:00:00 2001 From: zhangming <543802214@qq.com> Date: Tue, 18 Jul 2023 23:40:12 +0800 Subject: [PATCH] fixbug-ratelimit-config --- store/postgresql/instance.go | 11 ----------- store/postgresql/ratelimit_config.go | 11 ++++++----- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/store/postgresql/instance.go b/store/postgresql/instance.go index c15f858..7704666 100644 --- a/store/postgresql/instance.go +++ b/store/postgresql/instance.go @@ -979,17 +979,6 @@ func addMainInstance(tx *BaseTx, instance *model.Instance) error { "cmdb_region, cmdb_zone, cmdb_idc, priority, revision, ctime, mtime) " + "values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, " + "$15, $16, $17, $18, $19)" - // 此语句暂时留存,ON CONFLICT误法仅支持postgreSQL-11以上的版本 - /*str := ` - INSERT INTO instance(id, service_id, vpc_id, host, port, protocol, version, health_status, isolate, - weight, enable_health_check, logic_set, cmdb_region, cmdb_zone, cmdb_idc, priority, revision, ctime, mtime) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) - ON CONFLICT (id, service_id) DO - UPDATE - SET service_id = $20, vpc_id = $21, host = $22, port = $23, protocol = $24, version = $25, - health_status = $26, isolate = $27, weight = $28, enable_health_check = $29, - logic_set = $30, cmdb_region = $31, cmdb_zone = $32, cmdb_idc = $33, priority = $34, - revision = $35, ctime = $36, mtime = $37`*/ stmt, err := tx.Prepare(str) if err != nil { return err diff --git a/store/postgresql/ratelimit_config.go b/store/postgresql/ratelimit_config.go index 1f8293b..38ac5c4 100644 --- a/store/postgresql/ratelimit_config.go +++ b/store/postgresql/ratelimit_config.go @@ -72,15 +72,16 @@ func (rls *rateLimitStore) createRateLimit(limit *model.RateLimit) error { etimeStr := limitToEtimeStr(limit) // 新建限流规则 - str := fmt.Sprintf("insert into ratelimit_config(id, name, disable, service_id, "+ - "method, labels, priority, rule, revision, ctime, mtime, etime) "+ - "values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11, %s)", etimeStr) + str := "insert into ratelimit_config(id, name, disable, service_id, " + + "method, labels, priority, rule, revision, ctime, mtime, etime) " + + "values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)" stmt, err := tx.Prepare(str) if err != nil { return err } - if _, err = stmt.Exec(limit.ID, limit.Name, limit.Disable, limit.ServiceID, limit.Method, limit.Labels, - limit.Priority, limit.Rule, limit.Revision, GetCurrentTimeFormat(), GetCurrentTimeFormat()); err != nil { + if _, err = stmt.Exec(limit.ID, limit.Name, limit.Disable, limit.ServiceID, limit.Method, + limit.Labels, limit.Priority, limit.Rule, limit.Revision, GetCurrentTimeFormat(), + GetCurrentTimeFormat(), etimeStr); err != nil { log.Errorf("[Store][database] create rate limit(%+v), sql %s err: %s", limit, str, err.Error()) return err }