简体   繁体   中英

Batching of ACL requests for Google Documents via the API is fairly slow

I'm using version 3 (yes I know there is google drive API) and I'm trying to batch ACL requests as per here .

I've run a test in the google playground (as well as in my own code) to add 150 users as "writer" (role) to a document.

The xml looks something like:

<feed xmlns="http://www.w3.org/2005/Atom"
    xmlns:gAcl="http://schemas.google.com/acl/2007"
    xmlns:batch="http://schemas.google.com/gdata/batch">
  <category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/acl/2007#accessRule"/>
  <entry>
<id>https://docs.google.com/feeds/default/private/full/document:1111/acl/user:owner@example.com</id>
    <batch:operation type="query"/>
  </entry>
<entry><batch:id>1</batch:id><batch:operation type="insert"/><gAcl:role value="writer"/><gAcl:scope type="user" value="test1@example.com"/></entry>
<entry><batch:id>2</batch:id><batch:operation type="insert"/><gAcl:role value="writer"/><gAcl:scope type="user" value="test2@example.com"/></entry>
....
<entry><batch:id>150</batch:id><batch:operation type="insert"/><gAcl:role value="writer"/><gAcl:scope type="user" value="test150@example.com"/></entry>
</feed>

Processing this takes > 60 seconds and then the response comes back with a 500 error. It does seem to add all 150 but it takes a while. If I was to directly add 150 email addresses in the text area right in the google sharing dialog it takes a shorter period (8-10).

Am I not using the API correctly? Does the API not mimic the google sharing UI interface?

UPDATE: In looking at this further it looks like the batch api is really just saving you time "across the wire" but on the server side (google) it's just sending in the requests one at a time. I can see that if I directly add the 150 email addresses in the text area right in the google sharing dialog it takes 8-10 seconds, then if I add 151 it take 8-10 seconds. This tells me that google is validating the new entry against the existing list. With direct online interaction it's taking all 150 at once; with batch it's taking one at a time and validating after each one- which comes out to 5+ minutes total time.

If you are making these changes to a large number of files and the list of users to add is at least sometimes the same, you should consider putting the users into a Google Group. Then you can simply add the google group to the file ACL significantly cutting down on the number of API calls and time taken.

So if 2 files need to be shared with 150 users, using your current method is going to take the equivalent of 150 API calls (even though the network traffic is batched). This results in about 300 API calls.

If 2 files are shared using the group method, sharing the 1st file will take 152 API calls (1 API call to provision the group, 150 API calls to add the users as members and 1 API call to share the file with the group). But sharing the 2nd file will only take 1 API call. This results in only 153 API calls.

You could also lump your files into collections and share the collection instead of individual files to cut down on the number of API calls needed.

The Group Provisioning API call is documented at: https://developers.google.com/google-apps/provisioning/#creating_a_group

The Add Member to Group API call is documented at: https://developers.google.com/google-apps/provisioning/#adding_a_member_to_a_group

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM