Skip to content
This repository was archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
- Improving the performance of sanitize sql string for key ⚡
Browse files Browse the repository at this point in the history
- Fix bug in stmt exec args 🐛
- Fix doc for encode 💡
  • Loading branch information
fairyhunter13 committed Jan 28, 2021
1 parent d8e5ab8 commit 5fd8896
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion caches/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"io"
)

// md5 hash string
// Md5 hash string
func Md5(str string) string {
m := md5.New()
io.WriteString(m, str)
Expand Down
9 changes: 4 additions & 5 deletions session_stmt_cache.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package xorm

import (
"regexp"
"strings"
"sync"

"github.com/cespare/xxhash"
"github.com/fairyhunter13/xorm/core"
)

var (
stmtCache = make(map[uint64]*core.Stmt, 0) //key: xxhash of sqlstring+len(sqlstring)
mutex = new(sync.RWMutex)
regexWhiteSpaceCharacter = regexp.MustCompile(`[\s]`)
stmtCache = make(map[uint64]*core.Stmt, 0) //key: xxhash of sanitized sqlstring
mutex = new(sync.RWMutex)
)

func getKey(sqlStr string) string {
return regexWhiteSpaceCharacter.ReplaceAllString(sqlStr, "")
return strings.Join(strings.Fields(sqlStr), "")
}

func (session *Session) doPrepare(db *core.DB, sqlStr string) (stmt *core.Stmt, err error) {
Expand Down

0 comments on commit 5fd8896

Please sign in to comment.