a little perfomance improved
This commit is contained in:
parent
781062130a
commit
da96e0cc86
|
@ -58,7 +58,7 @@ type Engine struct {
|
||||||
DataSourceName string
|
DataSourceName string
|
||||||
dialect dialect
|
dialect dialect
|
||||||
Tables map[reflect.Type]*Table
|
Tables map[reflect.Type]*Table
|
||||||
mutex *sync.Mutex
|
mutex *sync.RWMutex
|
||||||
ShowSQL bool
|
ShowSQL bool
|
||||||
ShowErr bool
|
ShowErr bool
|
||||||
ShowDebug bool
|
ShowDebug bool
|
||||||
|
@ -421,12 +421,14 @@ func (engine *Engine) Having(conditions string) *Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) autoMapType(t reflect.Type) *Table {
|
func (engine *Engine) autoMapType(t reflect.Type) *Table {
|
||||||
engine.mutex.Lock()
|
engine.mutex.RLock()
|
||||||
defer engine.mutex.Unlock()
|
|
||||||
table, ok := engine.Tables[t]
|
table, ok := engine.Tables[t]
|
||||||
|
engine.mutex.RUnlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
table = engine.mapType(t)
|
table = engine.mapType(t)
|
||||||
|
engine.mutex.Lock()
|
||||||
engine.Tables[t] = table
|
engine.Tables[t] = table
|
||||||
|
engine.mutex.Unlock()
|
||||||
}
|
}
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
2
xorm.go
2
xorm.go
|
@ -49,7 +49,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.Tables = make(map[reflect.Type]*Table)
|
engine.Tables = make(map[reflect.Type]*Table)
|
||||||
engine.mutex = &sync.Mutex{}
|
engine.mutex = &sync.RWMutex{}
|
||||||
engine.TagIdentifier = "xorm"
|
engine.TagIdentifier = "xorm"
|
||||||
|
|
||||||
engine.Filters = append(engine.Filters, &IdFilter{})
|
engine.Filters = append(engine.Filters, &IdFilter{})
|
||||||
|
|
Loading…
Reference in New Issue