Commit eb5462f8 authored by hujiebin's avatar hujiebin

fix:batchGet

parent 5522be36
...@@ -68,10 +68,7 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) { ...@@ -68,10 +68,7 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) {
end = len(userIds) end = len(userIds)
} }
start := 0 start := 0
for end <= len(userIds) { for start < len(userIds) {
if end > len(userIds) {
end = len(userIds)
}
tmp := make([]UserVip, 0) tmp := make([]UserVip, 0)
err := mysql.Db.Where("user_id IN ?", userIds[start:end]).Find(&tmp).Error err := mysql.Db.Where("user_id IN ?", userIds[start:end]).Find(&tmp).Error
if err != nil { if err != nil {
...@@ -84,6 +81,9 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) { ...@@ -84,6 +81,9 @@ func BatchGetVips(userIds []uint64) (map[uint64]*int64, error) {
} }
start += 500 start += 500
end += 500 end += 500
if end > len(userIds) {
end = len(userIds)
}
//mylogrus.MyLog.Infof("BatchGetVips start:%v-end:%v", start, end) //mylogrus.MyLog.Infof("BatchGetVips start:%v-end:%v", start, end)
} }
......
...@@ -18,7 +18,7 @@ func TestGetUserMap(t *testing.T) { ...@@ -18,7 +18,7 @@ func TestGetUserMap(t *testing.T) {
func TestGetUserVipMap(t *testing.T) { func TestGetUserVipMap(t *testing.T) {
var userIds []uint64 var userIds []uint64
for i := 0; i < 1500; i++ { for i := 0; i < 10502; i++ {
userIds = append(userIds, 7642) userIds = append(userIds, 7642)
} }
res, err := user_m.BatchGetVips(userIds) res, err := user_m.BatchGetVips(userIds)
......
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