Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit f1f1c5e

Browse files
committed
Revert "perf(123pan): optimize rate limiting (AlistGo#6859)"
This reverts commit AlistGo#6859, which introduced performance enhancements in AlistGo#6859. Unfortunately, these changes led to unintended consequences resulting in account bans. The revert is necessary until a more thorough review and testing can be conducted to ensure no negative impacts on account status.
1 parent af9c6af commit f1f1c5e

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

drivers/123/driver.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (d *Pan123) Drop(ctx context.Context) error {
5353
}
5454

5555
func (d *Pan123) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
56-
files, err := d.getFiles(ctx, dir.GetID(), dir.GetName())
56+
files, err := d.getFiles(dir.GetID(), dir.GetName())
5757
if err != nil {
5858
return nil, err
5959
}
@@ -247,6 +247,9 @@ func (d *Pan123) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
247247
}
248248
_, err = uploader.UploadWithContext(ctx, input)
249249
}
250+
if err != nil {
251+
return err
252+
}
250253
_, err = d.request(UploadComplete, http.MethodPost, func(req *resty.Request) {
251254
req.SetBody(base.Json{
252255
"fileId": resp.Data.FileId,
@@ -255,12 +258,11 @@ func (d *Pan123) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
255258
return err
256259
}
257260

258-
func (d *Pan123) APIRateLimit(ctx context.Context, api string) error {
259-
value, _ := d.apiRateLimit.LoadOrStore(api,
260-
rate.NewLimiter(rate.Every(700*time.Millisecond), 1))
261-
limiter := value.(*rate.Limiter)
262-
263-
return limiter.Wait(ctx)
261+
func (d *Pan123) APIRateLimit(api string) bool {
262+
limiter, _ := d.apiRateLimit.LoadOrStore(api,
263+
rate.NewLimiter(rate.Every(time.Millisecond*700), 1))
264+
ins := limiter.(*rate.Limiter)
265+
return ins.Allow()
264266
}
265267

266268
var _ driver.Driver = (*Pan123)(nil)

drivers/123/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package _123
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"hash/crc32"
@@ -15,7 +14,7 @@ import (
1514

1615
"github.com/alist-org/alist/v3/drivers/base"
1716
"github.com/alist-org/alist/v3/pkg/utils"
18-
"github.com/go-resty/resty/v2"
17+
resty "github.com/go-resty/resty/v2"
1918
jsoniter "github.com/json-iterator/go"
2019
log "github.com/sirupsen/logrus"
2120
)
@@ -234,14 +233,15 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
234233
return body, nil
235234
}
236235

237-
func (d *Pan123) getFiles(ctx context.Context, parentId string, name string) ([]File, error) {
236+
func (d *Pan123) getFiles(parentId string, name string) ([]File, error) {
238237
page := 1
239238
total := 0
240239
res := make([]File, 0)
241240
// 2024-02-06 fix concurrency by 123pan
242241
for {
243-
if err := d.APIRateLimit(ctx, FileList); err != nil {
244-
return nil, err
242+
if !d.APIRateLimit(FileList) {
243+
time.Sleep(time.Millisecond * 200)
244+
continue
245245
}
246246
var resp Files
247247
query := map[string]string{

drivers/123_share/driver.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (d *Pan123Share) Drop(ctx context.Context) error {
4545

4646
func (d *Pan123Share) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
4747
// TODO return the files list, required
48-
files, err := d.getFiles(ctx, dir.GetID())
48+
files, err := d.getFiles(dir.GetID())
4949
if err != nil {
5050
return nil, err
5151
}
@@ -150,12 +150,11 @@ func (d *Pan123Share) Put(ctx context.Context, dstDir model.Obj, stream model.Fi
150150
// return nil, errs.NotSupport
151151
//}
152152

153-
func (d *Pan123Share) APIRateLimit(ctx context.Context, api string) error {
154-
value, _ := d.apiRateLimit.LoadOrStore(api,
155-
rate.NewLimiter(rate.Every(700*time.Millisecond), 1))
156-
limiter := value.(*rate.Limiter)
157-
158-
return limiter.Wait(ctx)
153+
func (d *Pan123Share) APIRateLimit(api string) bool {
154+
limiter, _ := d.apiRateLimit.LoadOrStore(api,
155+
rate.NewLimiter(rate.Every(time.Millisecond*700), 1))
156+
ins := limiter.(*rate.Limiter)
157+
return ins.Allow()
159158
}
160159

161160
var _ driver.Driver = (*Pan123Share)(nil)

drivers/123_share/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package _123Share
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"hash/crc32"
@@ -81,12 +80,13 @@ func (d *Pan123Share) request(url string, method string, callback base.ReqCallba
8180
return body, nil
8281
}
8382

84-
func (d *Pan123Share) getFiles(ctx context.Context, parentId string) ([]File, error) {
83+
func (d *Pan123Share) getFiles(parentId string) ([]File, error) {
8584
page := 1
8685
res := make([]File, 0)
8786
for {
88-
if err := d.APIRateLimit(ctx, FileList); err != nil {
89-
return nil, err
87+
if !d.APIRateLimit(FileList) {
88+
time.Sleep(time.Millisecond * 200)
89+
continue
9090
}
9191
var resp Files
9292
query := map[string]string{

0 commit comments

Comments
 (0)