perf(123pan): optimize rate limiting (#6859)

- eliminating fixed 200 ms delay in getFiles to prevent thread starvation
- allowing cancellation via context to mitigate potential DoS attacks by immediately cancelling excessive requests
This commit is contained in:
seiuneko
2024-07-25 20:08:59 +08:00
committed by GitHub
parent d4e3355f56
commit 5fa70e4010
4 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,7 @@
package _123Share
import (
"context"
"errors"
"fmt"
"hash/crc32"
@ -80,13 +81,12 @@ func (d *Pan123Share) request(url string, method string, callback base.ReqCallba
return body, nil
}
func (d *Pan123Share) getFiles(parentId string) ([]File, error) {
func (d *Pan123Share) getFiles(ctx context.Context, parentId string) ([]File, error) {
page := 1
res := make([]File, 0)
for {
if !d.APIRateLimit(FileList) {
time.Sleep(time.Millisecond * 200)
continue
if err := d.APIRateLimit(ctx, FileList); err != nil {
return nil, err
}
var resp Files
query := map[string]string{