Commit 7a0f7c75 authored by hujiebin's avatar hujiebin

分批获取userIds

parent 7f229adb
......@@ -85,12 +85,28 @@ func GetUsersByIds(model *domain.Model, userIds []mysql.ID) ([]User, error) {
return users, nil
}
// 分批获取userIds
func GetUserMapByIds(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]User, error) {
rows, err := GetUsersByIds(model, userIds)
if err != nil {
return nil, err
}
result := make(map[mysql.ID]User, 0)
end := 500
if end > len(userIds) {
end = len(userIds)
}
var rows []User
start := 0
for end <= len(userIds) {
if end > len(userIds) {
end = len(userIds)
}
tmp, err := GetUsersByIds(model, userIds[start:end])
if err != nil {
return result, err
} else {
rows = append(rows, tmp...)
}
start += 500
end += 500
}
for _, i := range rows {
result[i.ID] = i
}
......
package test
import (
"git.hilo.cn/hilo-common/domain"
"hilo-group/domain/model/user_m"
"testing"
)
func TestGetUserMap(t *testing.T) {
var userIds []uint64
for i := 0; i < 10502; i++ {
userIds = append(userIds, 7642)
}
res, err := user_m.GetUserMapByIds(domain.CreateModelNil(), userIds)
t.Logf("%v-%v", res, err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment