This commit is contained in:
parent
b0839b4c3b
commit
cbaef38589
|
@ -18,8 +18,6 @@ func ImportUserIdMap() {
|
|||
}
|
||||
ctx := context.Background()
|
||||
|
||||
userIdMaps := make([]*dbstruct.UserIdMap, 0)
|
||||
|
||||
// 打乱
|
||||
list := make([]int64, 0)
|
||||
for i := int64(1000000); i < 100000000; i++ {
|
||||
|
@ -29,6 +27,20 @@ func ImportUserIdMap() {
|
|||
list[i], list[j] = list[j], list[i]
|
||||
})
|
||||
|
||||
for i := 0; i < len(list); i += 1000000 {
|
||||
lower := i
|
||||
upper := i + 999999
|
||||
if upper >= len(list) {
|
||||
upper = len(list) - 1
|
||||
}
|
||||
go ImportAsList(mcli, ctx, list[lower:upper])
|
||||
}
|
||||
|
||||
fmt.Printf("Import into test success")
|
||||
}
|
||||
|
||||
func ImportAsList(mcli *mongo.Mongo, ctx context.Context, list []int64) {
|
||||
userIdMaps := make([]*dbstruct.UserIdMap, 0)
|
||||
for i := range list {
|
||||
seq := int64(1000000) + int64(i)
|
||||
userId := list[i]
|
||||
|
@ -44,13 +56,10 @@ func ImportUserIdMap() {
|
|||
userIdMaps = make([]*dbstruct.UserIdMap, 0)
|
||||
}
|
||||
}
|
||||
|
||||
if len(userIdMaps) > 0 {
|
||||
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateMappedUserIds err :%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Import into test success")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue