refactor: fix deepsource analyze

This commit is contained in:
Cr 2021-09-07 09:51:33 +08:00
parent 47f9746e11
commit b1fbaa71c3
No known key found for this signature in database
GPG Key ID: E6C6812B87229952

View File

@ -108,11 +108,11 @@ var (
) )
// get model info and model reflect value // get model info and model reflect value
func (*ormBase) getMiInd(md interface{}) (mi *modelInfo, ind reflect.Value) { func (*ormBase) getMi(md interface{}) (mi *modelInfo) {
val := reflect.ValueOf(md) val := reflect.ValueOf(md)
ind = reflect.Indirect(val) ind := reflect.Indirect(val)
typ := ind.Type() typ := ind.Type()
mi = getModelInfo(typ) mi = getTypeMi(typ)
return return
} }
@ -124,11 +124,11 @@ func (*ormBase) getPtrMiInd(md interface{}) (mi *modelInfo, ind reflect.Value) {
if val.Kind() != reflect.Ptr { if val.Kind() != reflect.Ptr {
panic(fmt.Errorf("<Ormer> cannot use non-ptr model struct `%s`", getFullName(typ))) panic(fmt.Errorf("<Ormer> cannot use non-ptr model struct `%s`", getFullName(typ)))
} }
mi = getModelInfo(typ) mi = getTypeMi(typ)
return return
} }
func getModelInfo(mdTyp reflect.Type) *modelInfo { func getTypeMi(mdTyp reflect.Type) *modelInfo {
name := getFullName(mdTyp) name := getFullName(mdTyp)
if mi, ok := modelCache.getByFullName(name); ok { if mi, ok := modelCache.getByFullName(name); ok {
return mi return mi
@ -242,7 +242,7 @@ func (o *ormBase) InsertMultiWithCtx(ctx context.Context, bulk int, mds interfac
if bulk <= 1 { if bulk <= 1 {
for i := 0; i < sind.Len(); i++ { for i := 0; i < sind.Len(); i++ {
ind := reflect.Indirect(sind.Index(i)) ind := reflect.Indirect(sind.Index(i))
mi, _ := o.getMiInd(ind.Interface()) mi := o.getMi(ind.Interface())
id, err := o.alias.DbBaser.Insert(ctx, o.db, mi, ind, o.alias.TZ) id, err := o.alias.DbBaser.Insert(ctx, o.db, mi, ind, o.alias.TZ)
if err != nil { if err != nil {
return cnt, err return cnt, err
@ -253,7 +253,7 @@ func (o *ormBase) InsertMultiWithCtx(ctx context.Context, bulk int, mds interfac
cnt++ cnt++
} }
} else { } else {
mi, _ := o.getMiInd(sind.Index(0).Interface()) mi := o.getMi(sind.Index(0).Interface())
return o.alias.DbBaser.InsertMulti(ctx, o.db, mi, sind, bulk, o.alias.TZ) return o.alias.DbBaser.InsertMulti(ctx, o.db, mi, sind, bulk, o.alias.TZ)
} }
return cnt, nil return cnt, nil