a little performance improved
This commit is contained in:
parent
c31c21b051
commit
a76d74804f
|
@ -27,7 +27,7 @@ type Engine struct {
|
|||
dialect core.Dialect
|
||||
Tables map[reflect.Type]*core.Table
|
||||
|
||||
mutex *sync.Mutex
|
||||
mutex *sync.RWMutex
|
||||
ShowSQL bool
|
||||
ShowErr bool
|
||||
ShowDebug bool
|
||||
|
@ -388,12 +388,14 @@ func (engine *Engine) Having(conditions string) *Session {
|
|||
}
|
||||
|
||||
func (engine *Engine) autoMapType(t reflect.Type) *core.Table {
|
||||
engine.mutex.Lock()
|
||||
defer engine.mutex.Unlock()
|
||||
engine.mutex.RLock()
|
||||
table, ok := engine.Tables[t]
|
||||
engine.mutex.RUnlock()
|
||||
if !ok {
|
||||
table = engine.mapType(t)
|
||||
engine.mutex.Lock()
|
||||
engine.Tables[t] = table
|
||||
engine.mutex.Unlock()
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
|
4
xorm.go
4
xorm.go
|
@ -50,12 +50,12 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
|||
DataSourceName: dataSourceName, dialect: dialect,
|
||||
tableCachers: make(map[reflect.Type]core.Cacher)}
|
||||
|
||||
engine.SetMapper(core.SnakeMapper{})
|
||||
engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper)))
|
||||
|
||||
engine.Filters = dialect.Filters()
|
||||
|
||||
engine.Tables = make(map[reflect.Type]*core.Table)
|
||||
engine.mutex = &sync.Mutex{}
|
||||
engine.mutex = &sync.RWMutex{}
|
||||
engine.TagIdentifier = "xorm"
|
||||
|
||||
engine.Logger = os.Stdout
|
||||
|
|
Loading…
Reference in New Issue