1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-22 13:19:02 +08:00

Merge pull request #125 from lhcn/concurrent_fix

fix concurrent map write
This commit is contained in:
zu1k 2022-07-28 12:30:58 +08:00 committed by GitHub
commit 3709ae8ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -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 (

View File

@ -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
}