【发布时间】:2016-07-16 13:33:16
【问题描述】:
我有一个关于谷歌应用引擎的项目,并且有几个功能使用 驱动 Java API。
另外,我正在使用“com.google.appengine.api.users.User;”
当我使用某些功能时,例如:createDocument:
public FileResponse createDocument(FileRequest file, @Named("visibility") @Nullable String visibility, User user) throws IOException, OAuthRequestException,
BadRequestException
{
Utils.validateAuthenticatedUser(user);
file.setValidator(new FileRequestValidator(FileRequestValidator.FileRequestType.CREATE));
file.validate(file);
Drive drive = new Drive.Builder(Globals.httpTransport, Globals.jsonFactory, Authenticator.credential(Constants.DRIVE_SCOPE, file.getDomainUser())).setApplicationName(
"My - APP").build();
File newFile = null;
try
{
Drive.Files.Insert insert = drive.files().insert(file.getFile());
if (visibility != null) insert.setVisibility(visibility);
newFile = insert.execute();
return new FileResponse(newFile);
} catch (Exception e)
{
logger.severe("An error occurred: " + e.getMessage());
throw new OAuthRequestException(e.getMessage());
}
}
此功能正在运行,但需要超过 920 毫秒。有办法优化它吗?甚至向谷歌支付更多费用。
我们可以看到700毫秒的时间属于urlFetch
【问题讨论】:
-
文档的创建必须在用户收到响应之前完成吗?通常,我会延迟资产的创建,首先给交互式用户他们的 http 响应,然后在任务中创建文档。
-
感谢您的回复。是的,我们的用户正在等待文档准备好,然后在得到响应后,他可以进入文件。
-
对用户的响应是否取决于创建的文档的内容?您仍然可以在异步任务中创建文档,并为调用者提供一个句柄,允许他们访问新文档,前提是创建在他们尝试访问之前完成。如果请求在创建完成之前发出,请求者可以在那个时候延迟,而不是在初始调用期间。
标签: java google-app-engine google-drive-api