by Robin at 20240923
This commit is contained in:
parent
da3026fae5
commit
cb02d2f15c
|
@ -22,49 +22,46 @@ func ImportUserIdMap() {
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
userIdSeq, err := mcli.GetUserIdImportSeq(ctx)
|
for i := 0; i < 100; i++ {
|
||||||
if err != nil {
|
pathurl := fmt.Sprintf("/app/data_prep/file/user_id_map%v.txt", i)
|
||||||
fmt.Printf("GetUserIdImportSeq fail : %v", err)
|
go func(i int) {
|
||||||
return
|
fmt.Printf("Importing %dth", i)
|
||||||
}
|
infile, err := os.Open(pathurl)
|
||||||
|
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("CreateMappedUserIds err :%v", err)
|
fmt.Printf("Open File Err : %v", err)
|
||||||
}
|
}
|
||||||
}
|
reader := bufio.NewReader(infile)
|
||||||
if err == io.EOF {
|
userIdMaps := make([]*dbstruct.UserIdMap, 0)
|
||||||
err := mcli.CreateMappedUserIds(ctx, userIdMaps)
|
for {
|
||||||
if err != nil {
|
str, err := reader.ReadString('\n')
|
||||||
fmt.Printf("CreateMappedUserIds err :%v", err)
|
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")
|
fmt.Printf("Import into test success")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue