gpt4 book ai didi

google-app-engine - Google Drive API - 太慢了。

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:34 25 4
gpt4 key购买 nike

我刚刚开始研究 Google Drive API。我有一个问题,它太慢了。我使用文档中的方法。例如:

List<File> getFilesByParrentId(String Id, Drive service) throws IOException {

Children.List request = service.children().list(Id);
ChildList children = request.execute();

List<ChildReference> childList = children.getItems();
File file;

List<File> files = new ArrayList<File>();
for (ChildReference child : childList) {
file = getFilebyId(child.getId(), service);

if (file == null) {
continue;
} else if (file.getMimeType().equals(FOLDER_IDENTIFIER)) {
System.out.println(file.getTitle() + " AND "
+ file.getMimeType());
files.add(file);
}
}

return files;
}

private File getFilebyId(String fileId, Drive service) throws IOException {
File file = service.files().get(fileId).execute();
if (file.getExplicitlyTrashed() == null) {
return file;
}
return null;
}

问题:该方法有效,但速度太慢,需要大约 30 秒。

我该如何优化它?例如,不获取所有文件(仅文件夹,或仅文件)。或类似的东西。

最佳答案

你可以使用 q 参数和一些类似的东西:

service.files().list().setQ(mimeType != 'application/vnd.google-apps.folder and 'Id' in parents and trashed=false").execute();

这将为您提供所有不是文件夹、未被删除且其父级具有 id 的文件。全部在一个请求中。

顺便说一句,API 并不慢。您的算法提出了太多请求。

关于google-app-engine - Google Drive API - 太慢了。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com