forked from mirror/gorm
Use RWMutex
This commit is contained in:
parent
b923e78e81
commit
96d52f25b0
2
main.go
2
main.go
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
// DB contains information for current db connection
|
// DB contains information for current db connection
|
||||||
type DB struct {
|
type DB struct {
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
Value interface{}
|
Value interface{}
|
||||||
Error error
|
Error error
|
||||||
RowsAffected int64
|
RowsAffected int64
|
||||||
|
|
|
@ -40,11 +40,11 @@ func (s *ModelStruct) TableName(db *DB) string {
|
||||||
s.defaultTableName = tabler.TableName()
|
s.defaultTableName = tabler.TableName()
|
||||||
} else {
|
} else {
|
||||||
tableName := ToTableName(s.ModelType.Name())
|
tableName := ToTableName(s.ModelType.Name())
|
||||||
db.parent.Lock()
|
db.parent.RLock()
|
||||||
if db == nil || (db.parent != nil && !db.parent.singularTable) {
|
if db == nil || (db.parent != nil && !db.parent.singularTable) {
|
||||||
tableName = inflection.Plural(tableName)
|
tableName = inflection.Plural(tableName)
|
||||||
}
|
}
|
||||||
db.parent.Unlock()
|
db.parent.RUnlock()
|
||||||
s.defaultTableName = tableName
|
s.defaultTableName = tableName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,9 +167,9 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
||||||
// Get Cached model struct
|
// Get Cached model struct
|
||||||
isSingularTable := false
|
isSingularTable := false
|
||||||
if scope.db != nil && scope.db.parent != nil {
|
if scope.db != nil && scope.db.parent != nil {
|
||||||
scope.db.parent.Lock()
|
scope.db.parent.RLock()
|
||||||
isSingularTable = scope.db.parent.singularTable
|
isSingularTable = scope.db.parent.singularTable
|
||||||
scope.db.parent.Unlock()
|
scope.db.parent.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
hashKey := struct {
|
hashKey := struct {
|
||||||
|
|
Loading…
Reference in New Issue