Google Drive API response is very slow -
we using google drive v3 api manage documents in our web application. have simple use case in user clicks on button , backend needs copy 5-10 files source
destination
folder. have tested 6 files in source folder , api took 7 seconds. have used batching invoke copy file api. following code same:
adding requests queue:
for(template template: templates) { file file = new file(); file.setparents(collections.singletonlist(parentfileid)); file.setname(template.getname()); file.setwriterscanshare(false); file.setviewerscancopycontent(false); map<string, string> appproperties = new hashmap<>(); appproperties.put(template_code_prop_name, template.getcode()); file.setappproperties(appproperties); driveservice.files().copy(template.getfileid(), file) .setfields("id, name, appproperties, webviewlink, iconlink, mimetype") .queue(batch, callback); }
handle response after batch executed successfully:
jsonbatchcallback<file> callback = new jsonbatchcallback<file>() { @override public void onsuccess(file file, httpheaders responseheaders) throws ioexception { log.info("copied file - " + file.getname() + " " + file.getid()); } @override public void onfailure(googlejsonerror e, httpheaders responseheaders) throws ioexception { log.severe("failed copy file " + e.getcode() + " " + e.getmessage()); throw new exception(); } };
i have followed best practices recommended google:
- set fields required in response partial response instead of complete response
- use batching invoking api
the api taking 7 seconds complete simple task. bad performance user experience perspective. i know if expected delay or doing wrong here ?
Comments
Post a Comment