Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Etag and LastModifiedDate donot change after file editing

After editing a document in GoogleDrive, it seems that the LastModified value doesn't change immediately sometimes. It looks like the value will be updated in a few minutes.

I tried to fetch the Etag of the document by DriveSDK, it also happens to the Etag value.

This strange behavior stops me getting the document status (modified or not) at real time. Any suggestions will be highly appreciated.

[Sample Request and Response] The request is just GoogleDrive ListFiles : https://www.googleapis.com/drive/v2/files

Here's the part of the response JSON, and you can see that the ModifiedDate is earlier than ModifiedByMeDate.

 {
 "kind": "drive#fileList",
 "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/oKnf21kAcJKTCIycS597xCSR2bk\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files",
 "items": [
  {
   "kind": "drive#file",
   "id": "1lZjcJIf3Chuu5upFqtiqfTRnRw7*****rFL_tlO8A",
   "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/MTM1NDY5MzMyMzQ1Mg\"",
   "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A",
   "alternateLink": "https://docs.google.com/a/*****.com/document/d/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/edit",
   "embedLink": "https://docs.google.com/a/*****.com/document/d/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/preview",
   "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_11_document_list.png",
   "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=1lZjcJIf3Chuu5upFqtiq*****7wSUjbRurFL_tlO8A&v=22&s=AMedNnoAAAAAU*****UK74n3UiIg0L4TY-NwP3EaAU&sz=s220",
   "title": "TestFile",
   "mimeType": "application/vnd.google-apps.document",
   "labels": {
    "starred": false,
    "hidden": false,
    "trashed": false,
    "restricted": false,
    "viewed": true
   },
   "createdDate": "2012-07-24T08:14:13.918Z",
   "modifiedDate": "2012-12-06T01:49:57.982Z",
   "modifiedByMeDate": "2012-12-06T01:49:57.982Z",
   "lastViewedByMeDate": "2012-12-06T01:50:06.974Z",
   "parents": [
    {
     "kind": "drive#parentReference",
     "id": "0AJ-aGTt-gWksUk9PVA",
     "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/parents/0AJ-aGTt-gWksUk9PVA",
     "parentLink": "https://www.googleapis.com/drive/v2/files/0AJ-aGTt-gWksUk9PVA",
     "isRoot": true
    }
   ],
   "exportLinks": {
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "https://docs.google.com/feeds/download/documents/export/Export?id=1l*****huu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A&exportFormat=docx",
    "application/vnd.oasis.opendocument.text": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upF*****SUjbRurFL_tlO8A&exportFormat=odt",
    "text/html": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUj*****L_tlO8A&exportFormat=html",
    "application/rtf": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiq*****SUjbRurFL_tlO8A&exportFormat=rtf",
    "text/plain": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3Chuu5upFqtiqf*****SUjbRurFL_tlO8A&exportFormat=txt",
    "application/pdf": "https://docs.google.com/feeds/download/documents/export/Export?id=1lZjcJIf3C*****fTRnRw7wSUjbRurFL_tlO8A&exportFormat=pdf"
   },
   "userPermission": {
    "kind": "drive#permission",
    "etag": "\"3NNCnvnQuji-pODa6SMQ6atlc3M/6LfqbkrWujmUe1WSDkyhTxdIUCc\"",
    "id": "me",
    "selfLink": "https://www.googleapis.com/drive/v2/files/1lZjcJIf3Chuu5upFqtiqfTRnRw7wSUjbRurFL_tlO8A/permissions/me",
    "role": "owner",
    "type": "user"
   },
   "quotaBytesUsed": "0",
   "ownerNames": [
    "***** *****"
   ],
   "lastModifyingUserName": "***** *****",
   "editable": true,
   "writersCanShare": true,
   "appDataContents": false
  },
like image 884
asir6 Avatar asked Dec 05 '12 05:12

asir6


2 Answers

This doesn't answer the question but I would just like to comment on what etag and modifiedDate means on File resources. File etag seems to just directly correspond to the modifiedDate value. The second part of the etag (after the slash) is just an encoding of the modifiedDate.

In the Documents List API, there's a property called app:edited besides the updated property (which seems to correspond to modifiedDate here). The way these timestamps change are not clearly documented, but I've noticed that app:edited changes on virtually every change (e.g. starring of a file, even by another user if I remember correctly) and updated changes are more limited (e.g. for content modifications and permission changes). And the etag before directly corresponds to app:edited, which is good because a change of app:edited indicates that there was really a change (sometimes it changes too much though, like starring of a file by a different user, as it doesn't really affect the current user's metadata).

What I want to say is that I think Documents List's etag (and having the app:edited property) is better than the Drive API having modifiedDate only. The problem with the latter is that you don't have a reliable way to determine if a File resource has changed or not. For example, if you just like to check if a File resource has changed, you could've used the files.get method with an If-None-Match header using the etag. But etag doesn't always change because modifiedDate doesn't always change. It changes, for example, when there's new content, or changed ACL, or changed description, but does not change, for example, when trashed, or parents changed. When comparing two resources, you can't reliably determine which one is newer. Add the fact that modifiedDate can be set (e.g. it would be possible to set the modifiedDate to an earlier value, or even a constant value, and the etag with it). The intended purpose of etag is lost. There are many cases where we can't just rely on the changes list, and if etag behaves properly, it would be huge help for determining the changes that happened.

What I suggest is to restore the behavior of etag to be similar to the Documents List API. And to help in determining which resource has newer information, add back the app:edited property as well (I think just documenting the value of etag is enough, like officially saying that the second part is an encoding of a timestamp, so that we can rely on it to be always increasing). Also, I think it's better to just change the modifiedDate property on content modification, and nothing else (e.g. not with ACL changes or description changes).

Similarly, etag of Revision(List) resources of verbatim files is not very useful as well. Since the downloadUrl property changes regularly, the etags of each Revision and the whole list changes with it, rendering it useless (because you can't use it to check if the revisions didn't change). Good thing there is the md5Checksum property you can compare, but it's not reliable in some cases.

like image 57
user1828559 Avatar answered Oct 31 '22 15:10

user1828559


Google's infrastructure updates Google docs asynchronously after updates. To my knowledge, this affects etag, thumbnails, and probably md5sum and certain modified dates.

Some documentation from Google confirming which items are asynchronous and which are synchronous would be tremendously useful to developers.

like image 25
pinoyyid Avatar answered Oct 31 '22 15:10

pinoyyid