fix: 优化获取最近分数的循环逻辑,确保正确处理记录数量并避免越界
This commit is contained in:
parent
8f91ac21df
commit
768ec1504f
@ -338,7 +338,7 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
|||||||
} `json:"playerScores"`
|
} `json:"playerScores"`
|
||||||
}
|
}
|
||||||
records := make([]RecordDataLite, 0)
|
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)
|
fullUrl := fmt.Sprintf(historyUrl, ssId, i+1)
|
||||||
resp, err := http.Get(fullUrl)
|
resp, err := http.Get(fullUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -354,8 +354,8 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
scores := response.Data
|
scores := response.Data
|
||||||
for k, score := range scores {
|
for _, score := range scores {
|
||||||
if k > count-1 {
|
if len(records) > count {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
record := RecordDataLite{
|
record := RecordDataLite{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user