mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 21:29:02 +08:00
fix concurrent map write
This commit is contained in:
parent
43388e84a9
commit
45953fcac5
@ -1,11 +1,15 @@
|
||||
package db
|
||||
|
||||
import "github.com/zu1k/nali/pkg/dbif"
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/zu1k/nali/pkg/dbif"
|
||||
)
|
||||
|
||||
var (
|
||||
dbNameCache = make(map[string]dbif.DB)
|
||||
dbTypeCache = make(map[dbif.QueryType]dbif.DB)
|
||||
queryCache = make(map[string]string)
|
||||
queryCache = sync.Map{}
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -70,14 +70,14 @@ func GetDB(typ dbif.QueryType) (db dbif.DB) {
|
||||
}
|
||||
|
||||
func Find(typ dbif.QueryType, query string) string {
|
||||
if result, found := queryCache[query]; found {
|
||||
return result
|
||||
if result, found := queryCache.Load(query); found {
|
||||
return result.(string)
|
||||
}
|
||||
result, err := GetDB(typ).Find(query)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
r := strings.Trim(result.String(), " ")
|
||||
queryCache[query] = r
|
||||
queryCache.Store(query, r)
|
||||
return r
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user