3
votes

I am currently working on an app that syncs one specific folder in a users Google Drive. I need to find when any of the files/folders in that specific folder have changed. The actual syncing process is easy, but I don't want to do a full sync every few seconds. I am condisering one of these methods:

1) Moniter the changes feed and look for any file changes
This method is easy but it will cause a sync if ANY file in the drive changes.

2) Frequently request all files in the whole drive eg. service.files().list().execute() and look for changes within the specific tree. This is a brute force approach. It will be too slow if the user has 1000's of files in their drive.

3) Start at the specific folder, and move down the folder tree looking for changes. This method will be fast if there are only a few directories in the specific tree, but it will still lead to numerous API requests.

Are there any better ways to find whether a specific folder and its contents have changed? Are there any optimisations I could apply to method 1,2 or 3.

2
doesnt developers.google.com/drive/v2/reference/changes give you a list of exactly what files changed?Joran Beasley
Yes but I have no way of knowing whether these files are in the specific folder tree that I am interested in. The changes feed only gives me the parent_ids of the changed files. I want to avoid storing all of the fileIds for the folder tree, but this may be the only option.Max Ferguson
Here is a similar problem with a solution. stackoverflow.com/questions/53470637/…Maros Mayer

2 Answers

1
votes

As you have correctly stated, you will need to keep (or work out) the file hierarchy for a changed file to know whether a file has changed within a folder tree.

There is no way of knowing directly from the changes feed whether a deeply nested file within a folder has been changed. Sorry.

0
votes

There are a couple of tricks that might help.

Firstly, if your app is using drive.file scope, then it will only see its own files. Depending on your specific situation, this may equate to your folder hierarchy.

Secondly, files can have multiple parents. So when creating a file in folder-top/folder-1/folder-1a/folder-1ai. you could declare both folder-1ai and folder-top as parents. Then you simply need to check for folder-top.