diff --git a/handler/scoresaber/bs50.go b/handler/scoresaber/bs50.go index bea618b..cce9289 100644 --- a/handler/scoresaber/bs50.go +++ b/handler/scoresaber/bs50.go @@ -638,31 +638,50 @@ func getAllScoreSaberScores(playerID string) ([]SongData, error) { if err != nil { return nil, fmt.Errorf("获取Best30失败: %v", err) } - for i, score := range topScores { - songData, err := convertScoreSaberToSongData(score, cwd) - if err != nil { - log.Printf("转换分数失败: %v", err) - continue - } - songData.IsBest30 = i < 30 - allSongs = append(allSongs, songData) - } - - // 获取Recent10 recentScores, err := getRecent10Scores(playerID) if err != nil { return nil, fmt.Errorf("获取Recent10失败: %v", err) } - for _, score := range recentScores { - songData, err := convertScoreSaberToSongData(score, cwd) - if err != nil { - log.Printf("转换分数失败: %v", err) - continue + wgAll := sync.WaitGroup{} + wgAll.Add(2) + go func() { + defer wgAll.Done() + wg := sync.WaitGroup{} + for i, score := range topScores { + wg.Add(1) + go func() { + defer wg.Done() + songData, err := convertScoreSaberToSongData(score, cwd) + if err != nil { + log.Printf("转换分数失败: %v", err) + return + } + songData.IsBest30 = i < 30 + allSongs[i] = songData + }() } - songData.IsBest30 = false - allSongs = append(allSongs, songData) - } - + wg.Wait() + }() + // 获取Recent10 + go func() { + defer wgAll.Done() + wg := sync.WaitGroup{} + for _, score := range recentScores { + wg.Add(1) + go func() { + defer wg.Done() + songData, err := convertScoreSaberToSongData(score, cwd) + if err != nil { + log.Printf("转换分数失败: %v", err) + return + } + songData.IsBest30 = false + allSongs = append(allSongs, songData) + }() + wg.Wait() + } + }() + wgAll.Wait() return allSongs, nil }