From 29a3f7e7c4f9ede186a1382c2831cd6660b9b06d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 25 Apr 2025 16:15:00 +0800 Subject: [PATCH 1/2] format code and add session level prepare stmt config --- gorm.go | 4 +++- internal/lru/lru.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gorm.go b/gorm.go index 15dec58a..dd1940ce 100644 --- a/gorm.go +++ b/gorm.go @@ -110,6 +110,8 @@ type DB struct { type Session struct { DryRun bool PrepareStmt bool + PrepareStmtMaxSize int + PrepareStmtTTL time.Duration NewDB bool Initialized bool SkipHooks bool @@ -273,7 +275,7 @@ func (db *DB) Session(config *Session) *DB { if v, ok := db.cacheStore.Load(preparedStmtDBKey); ok { preparedStmt = v.(*PreparedStmtDB) } else { - preparedStmt = NewPreparedStmtDB(db.ConnPool, db.Config.PrepareStmtMaxSize, db.Config.PrepareStmtTTL) + preparedStmt = NewPreparedStmtDB(db.ConnPool, config.PrepareStmtMaxSize, config.PrepareStmtTTL) db.cacheStore.Store(preparedStmtDBKey, preparedStmt) } diff --git a/internal/lru/lru.go b/internal/lru/lru.go index fbdffbba..4f21589a 100644 --- a/internal/lru/lru.go +++ b/internal/lru/lru.go @@ -1,7 +1,7 @@ package lru // golang -lru -//https://github.com/hashicorp/golang-lru +// https://github.com/hashicorp/golang-lru import ( "sync" "time" @@ -226,7 +226,7 @@ func (c *LRU[K, V]) KeyValues() map[K]V { continue } maps[ent.Key] = ent.Value - //keys = append(keys, ent.Key) + // keys = append(keys, ent.Key) } return maps } From c588e740e1617b89621d3d8a8efc033e002b6e51 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 25 Apr 2025 16:18:57 +0800 Subject: [PATCH 2/2] code format according to golinter ci --- gorm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gorm.go b/gorm.go index dd1940ce..d253736d 100644 --- a/gorm.go +++ b/gorm.go @@ -35,7 +35,7 @@ type Config struct { // PrepareStmt executes the given query in cached statement PrepareStmt bool // PrepareStmt cache support LRU expired, - //default maxsize=int64 Max value and ttl=1h + // default maxsize=int64 Max value and ttl=1h PrepareStmtMaxSize int PrepareStmtTTL time.Duration