How to get last modified date of folder inclusive of changes to child folders/files with Google Drive API

Viewed 30

I created a dropdown in my application that displays folders in a Google Drive based on a user's search. The dropdown shows both the name of the folder and the last modified date. However, Google does not update the last modified date of the parent folder when any of it's child folders/files are modified, it only updates in response to direct modifications to that specific folder. I've thought of two possible solutions, but I'm not really of fan of either and am looking for some other more performant/efficient solutions.

For example,

  1. After receiving the results from the user's query I could iterate over each result (i.e. each parent folder) and fetch a list of all it's children and then iterate through the last modified date for each child to return the most recent date. However, performing this on each autocomplete query would be slow and degrade the user experience as the user would have to wait for a few seconds after typing before the results load.

  2. I could have a separate background process outside of my application that runs every 1 minute and checks for file changes using the Changes: list resource and filters the changes that are related to the root folder where the dropdown options live. However, to do this I need to recursively travel up the parent tree to get to the root folder for each change because only the direct parent (not other ancestors) are accessible in the "parents" property of the File resource. I'd have to do this for each change just to determine if the change was related to a subfolder/file of the root folder (2-3 levels up). Which means each change would require another 2-3 api requests just to determine if it is even relevant. Keep in mind the number of changes in the change list is quite large.

Both of these solutions while viable seem pretty inefficient to me. Does anyone have a better suggestion as to how I can achieve this objective?

0 Answers
Related