Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search folders in batches to avoid 413 entity too large from drive api #228

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
search folders in batches to avoid 413 entity too large from drive api
tarekrached committed Oct 26, 2020
commit 51b46f11c731ca96193ca5777324d86a6e6819da
26 changes: 19 additions & 7 deletions server/search.js
Original file line number Diff line number Diff line change
@@ -6,22 +6,34 @@ const list = require('./list')
const log = require('./logger')

const driveId = process.env.DRIVE_ID
const MAX_FOLDERS_TO_SEARCH = 100 // got 413 entity too large at 129, this gives us some headroom

exports.run = async (query, driveType = 'team') => {
const authClient = await getAuth()
let folderIds
let allFolderIds

const drive = google.drive({version: 'v3', auth: authClient})

if (driveType === 'folder') {
folderIds = await getAllFolders({drive})
allFolderIds = await getAllFolders({drive})
}
log.debug(`searching ${allFolderIds.length} folders in chunks of ${MAX_FOLDERS_TO_SEARCH}`)

const files = await fullSearch({drive, query, folderIds, driveType})
.catch((err) => {
log.error(`Error when searching for ${query}, ${err}`)
throw err
})
const files = []

while (allFolderIds.length > 0) {
const folderIds = allFolderIds.splice(0, MAX_FOLDERS_TO_SEARCH)

const theseFiles = await fullSearch({drive, query, folderIds, driveType})
.catch((err) => {
log.error(`Error when searching for ${query}, ${err}`)
throw err
})

files.push(...theseFiles)
}

log.debug(`got ${files.length} results`)

const fileMetas = files
.map((file) => { return list.getMeta(file.id) || {} })