diff --git a/importfunc/import_user_id_map.go b/importfunc/import_user_id_map.go index a590dff..f6ce888 100644 --- a/importfunc/import_user_id_map.go +++ b/importfunc/import_user_id_map.go @@ -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") }