Skip to content

Commit

Permalink
optimize getColumnAsArray (go-gorm#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee authored and jinzhu committed Jan 2, 2019
1 parent 8316f94 commit 9f1a7f5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ func (scope *Scope) autoIndex() *Scope {
}

func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
resultMap := make(map[string][]interface{})
for _, value := range values {
indirectValue := indirect(reflect.ValueOf(value))

Expand All @@ -1327,7 +1328,10 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
}

if hasValue {
results = append(results, result)
h := fmt.Sprint(result...)
if _, exist := resultMap[h]; !exist {
resultMap[h] = result
}
}
}
case reflect.Struct:
Expand All @@ -1342,11 +1346,16 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
}

if hasValue {
results = append(results, result)
h := fmt.Sprint(result...)
if _, exist := resultMap[h]; !exist {
resultMap[h] = result
}
}
}
}

for _, v := range resultMap {
results = append(results, v)
}
return
}

Expand Down

0 comments on commit 9f1a7f5

Please sign in to comment.