1

Scenario:

  • I have multiple browser clients whose internet connection varies from very fast to super slow. Because of that they might not see same state of a document.

  • I'm using Google shortcut file since the document is actually being stored in database.

  • saving document to database is triggered from client-side.

Question: how do I know which client got the most up to date document that should be saved to the database?

Community
  • 1
  • 1
dev.e.loper
  • 35,446
  • 76
  • 161
  • 247

1 Answers1

2

You are right that you can't rely on any particular client being the most up to date at a particular time. There is no easy way to determine that, since that can change at any given instant. (Although you can make sure that you don't have any unsaved changes in a particular client by looking at the document save state.)

Rather than trying to do this based on client state, you can use the export capability that is part of the Drive API, which will give you a valid snapshot of the data with a revision number so you can track what version you have.

Note that this is a brand new feature, so its not yet well documented. The response is a json object with the appId, revision number, and a data field which contains a json version of the document. It looks something like this, for a document that has a collab list "list" and collab string "text" in the root:

{"appId":"788242802491","revision":17,
 "data":{"id":"root","type":"Map",
   "value":{
     "list":{"id":"gde9s8z5khjarls7o","type":"List","value":[]},
     "text":{"id":"gdef98qdhiq679af","type":"EditableString","value":"This is a test 2."}}}}
Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • Where is the valid snapshot coming from? Since I'm using shortcut file, no data is stored in central location(server), correct? – dev.e.loper Jul 16 '13 at 19:08
  • The realtime data model is always stored on the server. That is necessary for (among other things) a user to be able to come back and view it later. Using a shortcut file just means that you aren't storing any extra binary data apart from the realtime data model itself. (If you want to better understand how this all works, you might want to check out our behind the scenes talk from Google I/O http://www.youtube.com/watch?v=hv14PTbkIs0 ) – Cheryl Simon Jul 16 '13 at 19:21
  • I see. I guess there is another question as far as how long do I want to store these shortcut files? I assume I don't want them around forever, so do I delete them after last user exists realtime session? http://stackoverflow.com/questions/17579739/google-realtime-api-creating-and-removing-shortcut-file-in-google-drive – dev.e.loper Jul 16 '13 at 19:28