Paulo Pinto
Paulo Pinto

Reputation: 219

Google Drive API PHP is too slow?

I'm listing a tree inside a specific folder, but for every driveService->files->listFiles() it takes at least 1 second... How can i improve speed?

        $response = $driveService->files->listFiles(array(
            'q' => "'" . basename($dir) . "' in parents AND trashed = false ",
            'spaces' => 'drive',
            'pageToken' => $pageToken,
            'pageSize'=>1000,
            'fields' => 'files(id,mimeType)'));

Upvotes: 1

Views: 289

Answers (1)

pinoyyid
pinoyyid

Reputation: 22306

By requesting up to 1,000 results, the Google servers need to do a lot of internal work to find your files. The only way I can think of speeding it up would be to shard the files and run parallel queries with fewer files in each query. It comes down to whether you want to improve throughput or response time (they are different and often mutually exclusive).

N.B. In your code, you aren't including nextPageToken in your fields. This is almost certainly a bug! The "1,000" is only a maximum therefore GDrive reserves the right to return a small number of files and set nextPageToken to indicate that there are more files to be fetched.

Upvotes: 2

Related Questions