diff --git a/domain/model/user_m/vip.go b/domain/model/user_m/vip.go index f5643c94e585a03cdb1bd8fb69d6a70d171702a3..f7e7721ea77a4368041817dbb2fe4a5027a6578c 100644 --- a/domain/model/user_m/vip.go +++ b/domain/model/user_m/vip.go @@ -68,10 +68,7 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) { end = len(userIds) } start := 0 - for end <= len(userIds) { - if end > len(userIds) { - end = len(userIds) - } + for start < len(userIds) { tmp := make([]UserVip, 0) err := mysql.Db.Where("user_id IN ?", userIds[start:end]).Find(&tmp).Error if err != nil { @@ -84,6 +81,9 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) { } start += 500 end += 500 + if end > len(userIds) { + end = len(userIds) + } //mylogrus.MyLog.Infof("BatchGetVips start:%v-end:%v", start, end) } diff --git a/test/user_test.go b/test/user_test.go index b4310b7432bdb10acb303a19742a33a31f447bdb..8fbd3b8b589d79af4ddbfc3aeeeb6eea37e72689 100644 --- a/test/user_test.go +++ b/test/user_test.go @@ -18,7 +18,7 @@ func TestGetUserMap(t *testing.T) { func TestGetUserVipMap(t *testing.T) { var userIds []uint64 - for i := 0; i < 1500; i++ { + for i := 0; i < 10502; i++ { userIds = append(userIds, 7642) } res, err := user_m.BatchGetVips(userIds)