mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-03-15 03:20:32 +00:00
perf(baidu_netdisk): reduce the number of file listing requests (#2016)
* 本优化减少了百度网盘驱动下文件列表的请求次数,能加快文件浏览速度。此前只要文件夹下有至少一个文件,都会至少发出2次列表请求。 Signed-off-by: hcrgm <hcrgm@qq.com>
This commit is contained in:
@@ -152,7 +152,7 @@ func (d *BaiduNetdisk) postForm(pathname string, params map[string]string, form
|
||||
|
||||
func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
|
||||
start := 0
|
||||
limit := 200
|
||||
limit := 1000
|
||||
params := map[string]string{
|
||||
"method": "list",
|
||||
"dir": dir,
|
||||
@@ -168,7 +168,6 @@ func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
|
||||
for {
|
||||
params["start"] = strconv.Itoa(start)
|
||||
params["limit"] = strconv.Itoa(limit)
|
||||
start += limit
|
||||
var resp ListResp
|
||||
_, err := d.get("/xpan/file", params, &resp)
|
||||
if err != nil {
|
||||
@@ -187,6 +186,11 @@ func (d *BaiduNetdisk) getFiles(dir string) ([]File, error) {
|
||||
} else {
|
||||
res = append(res, resp.List...)
|
||||
}
|
||||
|
||||
if len(resp.List) < limit {
|
||||
break
|
||||
}
|
||||
start += limit
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user