From db84731d9dbfe9a8d3e1e526554be01ec036a5a4 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sat, 12 Jul 2025 00:34:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B9=B6=E5=8F=91=E5=A4=84?= =?UTF-8?q?=E7=90=86=20Best30=20=E5=92=8C=20Recent10=20=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/scoresaber/bs50.go | 59 +++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 20 deletions(-) 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 }