refactor: 并发处理 Best30 和 Recent10 的图片下载

This commit is contained in:
lixiangwuxian 2025-07-12 00:34:29 +08:00
parent 5ce7f7bba4
commit db84731d9d

View File

@ -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 {
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)
continue
return
}
songData.IsBest30 = i < 30
allSongs[i] = 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
}