谷歌驱动API - 订单很慢

时间:2017-11-27 10:55:21

标签: google-drive-api google-drive-android-api

(Note: This is a self-answering question)

我注意到orderBy folder,title非常慢,我该怎么办?

$ time curl 'https://content.googleapis.com/drive/v2/files?maxResults=10&orderBy=folder%2Ctitle&q=%27root%27%20in%20parents%20and%20trashed%3Dfalse&key=XXX' --compressed -H 'Authorization: Bearer XXX' -H 'X-Origin: https://explorer.apis.google.com'  -H 'If-None-Match: "XXX"'

完成需要大约11秒钟:

real    0m11.356s
user    0m0.008s
sys     0m0.016s

你可以test in API Explorer。查询是:

  • maxResults:10
  • ordeBy:文件夹,标题
  • q:' root'在父母和trashed = false

1 个答案:

答案 0 :(得分:-2)

<强> (Note: I'm self-answering my question)

API v3正在运行,如果可能,请考虑从v2迁移。它将减少到<1秒(v2中的字段title在v3中称为name,而v2中的maxResults在v3中称为pageSize

$ time curl 'https://content.googleapis.com/drive/v3/files?orderBy=folder%2Cname&pageSize=10&q=%27root%27%20in%20parents%20and%20trashed%3Dfalse&key=XXX' --compressed  -H 'Authorization: Bearer XXX' -H 'X-Requested-With: XMLHttpRequest' -H 'X-Origin: https://explorer.apis.google.com'
...
real    0m0.674s
user    0m0.024s
sys     0m0.004s

在第3版中,您还需要指定fields,例如(单击&#34;显示标准参数&#34;在&#34中扩展字段表单;试用它API资源管理器&#34;):

files(kind,id,name,size,mimeType,thumbnailLink)

更多:Migrate to Google Drive API v3 from Google Drive API v2