diff --git a/domain/model/user_m/user.go b/domain/model/user_m/user.go index 8a0dc8f0a2e47eeea9f84a7452163628abe2c06b..4561c1b43599060b933d5cb932d282726990e568 100644 --- a/domain/model/user_m/user.go +++ b/domain/model/user_m/user.go @@ -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 } diff --git a/test/user_test.go b/test/user_test.go new file mode 100644 index 0000000000000000000000000000000000000000..2c55f542eddc4da4cb5ea6ecf17f4ce841ad9882 --- /dev/null +++ b/test/user_test.go @@ -0,0 +1,16 @@ +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) +}