by Robin at 20240923

This commit is contained in:
Leufolium 2024-09-23 15:23:23 +08:00
parent da3026fae5
commit cb02d2f15c
1 changed files with 36 additions and 39 deletions

View File

@ -22,49 +22,46 @@ func ImportUserIdMap() {
}
ctx := context.Background()
userIdSeq, err := mcli.GetUserIdImportSeq(ctx)
if err != nil {
fmt.Printf("GetUserIdImportSeq fail : %v", err)
return
}
pathurl := fmt.Sprintf("/app/data_prep/file/user_id_map%v.txt", userIdSeq.Seq)
fmt.Printf("Importing %dth", userIdSeq.Seq)
infile, err := os.Open(pathurl)
if err != nil {
fmt.Printf("Open File Err : %v", err)
}
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)
for i := 0; i < 100; i++ {
pathurl := fmt.Sprintf("/app/data_prep/file/user_id_map%v.txt", i)
go func(i int) {
fmt.Printf("Importing %dth", i)
infile, err := os.Open(pathurl)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
fmt.Printf("Open File Err : %v", err)
}
}
if err == io.EOF {
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
if err != nil {
fmt.Printf("CreateMappedUserIds err :%v", err)
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
}
}
break
}
infile.Close()
fmt.Printf("%dth imported", i)
}(i)
}
infile.Close()
fmt.Printf("%dth imported", userIdSeq.Seq)
fmt.Printf("Import into test success")
}