Use RWMutex

This commit is contained in:
Emir Beganovic 2019-04-14 12:41:14 +04:00
parent b923e78e81
commit 96d52f25b0
2 changed files with 5 additions and 5 deletions

View File

@ -12,7 +12,7 @@ import (
// DB contains information for current db connection
type DB struct {
sync.Mutex
sync.RWMutex
Value interface{}
Error error
RowsAffected int64

View File

@ -40,11 +40,11 @@ func (s *ModelStruct) TableName(db *DB) string {
s.defaultTableName = tabler.TableName()
} else {
tableName := ToTableName(s.ModelType.Name())
db.parent.Lock()
db.parent.RLock()
if db == nil || (db.parent != nil && !db.parent.singularTable) {
tableName = inflection.Plural(tableName)
}
db.parent.Unlock()
db.parent.RUnlock()
s.defaultTableName = tableName
}
}
@ -167,9 +167,9 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
// Get Cached model struct
isSingularTable := false
if scope.db != nil && scope.db.parent != nil {
scope.db.parent.Lock()
scope.db.parent.RLock()
isSingularTable = scope.db.parent.singularTable
scope.db.parent.Unlock()
scope.db.parent.RUnlock()
}
hashKey := struct {