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