fix: 优化获取最近分数的循环逻辑,确保正确处理记录数量并避免越界

This commit is contained in:
lixiangwuxian 2025-04-12 21:32:55 +08:00
parent 8f91ac21df
commit 768ec1504f

View File

@ -338,7 +338,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
} `json:"playerScores"`
}
records := make([]RecordDataLite, 0)
for i := 0; i < count/8; i++ {
for i := range (count-1)/8 + 1 {
fullUrl := fmt.Sprintf(historyUrl, ssId, i+1)
resp, err := http.Get(fullUrl)
if err != nil {
@ -354,8 +354,8 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
return nil, err
}
scores := response.Data
for k, score := range scores {
if k > count-1 {
for _, score := range scores {
if len(records) > count {
break
}
record := RecordDataLite{