mirror of
https://github.com/astaxie/beego.git
synced 2025-06-14 04:00:39 +00:00
make stmt cache smaller
This commit is contained in:
@ -197,9 +197,9 @@ func getDbCreateSQL(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
|
||||
if strings.Contains(column, "%COL%") {
|
||||
column = strings.Replace(column, "%COL%", fi.column, -1)
|
||||
}
|
||||
|
||||
if fi.description != "" && al.Driver!=DRSqlite {
|
||||
column += " " + fmt.Sprintf("COMMENT '%s'",fi.description)
|
||||
|
||||
if fi.description != "" && al.Driver != DRSqlite {
|
||||
column += " " + fmt.Sprintf("COMMENT '%s'", fi.description)
|
||||
}
|
||||
|
||||
columns = append(columns, column)
|
||||
|
@ -18,10 +18,11 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
// DriverType database driver constant int.
|
||||
@ -424,7 +425,7 @@ func GetDB(aliasNames ...string) (*sql.DB, error) {
|
||||
}
|
||||
|
||||
type stmtDecorator struct {
|
||||
wg sync.WaitGroup
|
||||
wg sync.WaitGroup
|
||||
stmt *sql.Stmt
|
||||
}
|
||||
|
||||
@ -459,7 +460,9 @@ func newStmtDecorator(sqlStmt *sql.Stmt) *stmtDecorator {
|
||||
}
|
||||
|
||||
func newStmtDecoratorLruWithEvict() *lru.Cache {
|
||||
cache, _ := lru.NewWithEvict(1000, func(key interface{}, value interface{}) {
|
||||
// temporarily solution
|
||||
// we fixed this problem in v2.x
|
||||
cache, _ := lru.NewWithEvict(50, func(key interface{}, value interface{}) {
|
||||
value.(*stmtDecorator).destroy()
|
||||
})
|
||||
return cache
|
||||
|
@ -61,7 +61,7 @@ func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error
|
||||
con += " - " + err.Error()
|
||||
}
|
||||
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
||||
if LogFunc != nil{
|
||||
if LogFunc != nil {
|
||||
LogFunc(logMap)
|
||||
}
|
||||
DebugLog.Println(con)
|
||||
|
Reference in New Issue
Block a user