Skip to content

Commit 031b719

Browse files
authored
perf(baidu_netdisk): reduce the number of file listing requests (OpenListTeam#2016)
* 本优化减少了百度网盘驱动下文件列表的请求次数,能加快文件浏览速度。此前只要文件夹下有至少一个文件,都会至少发出2次列表请求。 Signed-off-by: hcrgm <hcrgm@qq.com>
1 parent d8417e0 commit 031b719

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/baidu_netdisk/util.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (d *BaiduNetdisk) postForm(pathname string, params map[string]string, form
152152

153153
func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
154154
start := 0
155-
limit := 200
155+
limit := 1000
156156
params := map[string]string{
157157
"method": "list",
158158
"dir": dir,
@@ -168,7 +168,6 @@ func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
168168
for {
169169
params["start"] = strconv.Itoa(start)
170170
params["limit"] = strconv.Itoa(limit)
171-
start += limit
172171
var resp ListResp
173172
_, err := d.get("/xpan/file", params, &resp)
174173
if err != nil {
@@ -187,6 +186,11 @@ func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
187186
} else {
188187
res = append(res, resp.List...)
189188
}
189+
190+
if len(resp.List) < limit {
191+
break
192+
}
193+
start += limit
190194
}
191195
return res, nil
192196
}

0 commit comments

Comments
 (0)