0

The files resource, which is returned by the files.list and other methods, includes a list of parents for each file. It would be extremely helpful if files also included some indication of children. An integer property with the count of children would be best, but a Boolean flag indicating whether children exist would be fine. Could that be added to the API, Google folks?

I ask because I'm writing an application that displays an expandable tree of the user's Google Drive contents. The tree initially displays the top level of their drive with all folders collapsed. As the user expands folders, new queries are sent to the GD API to get the contents of each one. However, empty folders are to be displayed without an expansion icon at all. In order to do that, as the list of children in a folder is processed, if a child is a folder, another query must be run for that specific folder to discover whether it has children. It would be so much better if the files resource included a count of its children or a flag indicating their existence. It would reduce the number of queries, network traffic, and processing time.

Mr. Lance E Sloan
  • 3,297
  • 5
  • 35
  • 50

2 Answers2

1

I doubt very much it will happen. The issue is that there could be thousands of children and to include an array of that size within the file object would break and time out.

The children feed https://developers.google.com/drive/v2/reference/children/list is there for that specific purpose, and supports pagination.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • That makes sense. Even though the `children` resource is small (only four properties), it could represent a lot of data if there are many of them. Since what I'd like to know is whether a file has children, I will edit my question. – Mr. Lance E Sloan Apr 03 '14 at 12:46
  • No harm putting in the feature request, and I understand the use case. I do something similar. I wouldn't hold your breath for a change to the API since I suspect this particular change would require a significant amount of Drive infrastructure processing to derive the count of children in realtime, or a data redesign to maintain a running count in the File object. – pinoyyid Apr 03 '14 at 13:11
  • Sure. Maybe the count of the children could be a problem. A Boolean flag should be ok, though. I hope to get an official response from one of the Google Drive team members, like @AliAfshar or the others. – Mr. Lance E Sloan Apr 03 '14 at 17:48
  • @pinoyyid It still puzzles me why the server can't return a number of items found (for any list query) without/before returning the list. I assume the total number of found items must be known to the server before any pagination takes place. And it would be helpful to the requesting app in order to build a progress bar, for instance. – seanpj Oct 11 '14 at 16:07
  • @seanpj I agree with your use case. I guess this is all massively distributed, so I doubt there is any one server that could authoritatively marshal the query results. The best workarounds I can think of are (a) run with maxresults 1000 and fields=items/id to get a long, skinny list, or (b) run a proxy on appengine that does the fetch-pagination and returns a count to the client. – pinoyyid Oct 11 '14 at 16:48
  • Thanks, (a) is exactly what I'm doing now. I use title instead of id, since it seems 'skinnier'. But it still takes a longer than a single number. It was just an idea that the 'proxy solution' could be build into the SDK. But I know I'm pushing it. – seanpj Oct 12 '14 at 02:23
0

Various work-around I found were all based on a looping solution over the children items count returned by each API call. Next API call must be then updated with the nextPageToken received from each response. A maxResult may be set to 1000 (max allowed).

Examples:

Community
  • 1
  • 1
Ronan
  • 4,311
  • 3
  • 19
  • 14