This commit is contained in:
Leufolium 2024-09-23 16:22:23 +08:00
parent 3f171d684c
commit e1abf6b18a
1 changed files with 35 additions and 36 deletions

View File

@ -23,45 +23,44 @@ func ImportUserIdMap() {
ctx := context.Background()
for i := 1; i < 100; i++ {
go func(i int) {
fmt.Printf("Importing %dth", i)
pathurl := fmt.Sprintf("/app/data_prep/file/user_id_map%v.txt", i)
infile, err := os.Open(pathurl)
if err != nil {
fmt.Printf("Open File Err : %v", err)
return
fmt.Printf("Importing %dth", i)
pathurl := fmt.Sprintf("/app/data_prep/file/user_id_map%v.txt", i)
infile, err := os.Open(pathurl)
if err != nil {
fmt.Printf("Open File Err : %v", err)
return
}
reader := bufio.NewReader(infile)
userIdMaps := make([]*dbstruct.UserIdMap, 0)
for {
str, err := reader.ReadString('\n')
if len(str) == 0 {
continue
}
reader := bufio.NewReader(infile)
userIdMaps := make([]*dbstruct.UserIdMap, 0)
for {
str, err := reader.ReadString('\n')
if len(str) == 0 {
continue
}
strs := strings.Split(str, ":")
seq, _ := strconv.Atoi(strs[0])
userId, _ := strconv.Atoi(strs[1])
userIdMaps = append(userIdMaps, &dbstruct.UserIdMap{
Seq: int64(seq),
UserId: int64(userId),
})
if len(userIdMaps) == 1000 {
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
}
}
if err == io.EOF {
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
}
break
strs := strings.Split(str, ":")
seq, _ := strconv.Atoi(strs[0])
userId, _ := strconv.Atoi(strs[1])
userIdMaps = append(userIdMaps, &dbstruct.UserIdMap{
Seq: int64(seq),
UserId: int64(userId),
})
if len(userIdMaps) == 1000 {
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
}
userIdMaps = make([]*dbstruct.UserIdMap, 0)
}
infile.Close()
fmt.Printf("%dth imported", i)
}(i)
if err == io.EOF {
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
}
break
}
}
infile.Close()
fmt.Printf("%dth imported", i)
}
fmt.Printf("Import into test success")