From b63a2cbfa7802133b7b328459a45278b97670c75 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 18 Oct 2022 08:16:40 -0700 Subject: [PATCH] Chunk calls to getFiles (fix #77) --- src/services/DavRequests.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/services/DavRequests.ts b/src/services/DavRequests.ts index 4b8b18af..9a1ecc3b 100644 --- a/src/services/DavRequests.ts +++ b/src/services/DavRequests.ts @@ -27,12 +27,31 @@ const IMAGE_MIME_TYPES = [ 'image/heic', ]; +const GET_FILE_CHUNK_SIZE = 50; + /** * Get file infos for list of files given Ids * @param fileIds list of file ids * @returns list of file infos */ -export async function getFiles(fileIds: number[]): Promise { + export async function getFiles(fileIds: number[]): Promise { + // Divide fileIds into chunks of GET_FILE_CHUNK_SIZE + const chunks = []; + for (let i = 0; i < fileIds.length; i += GET_FILE_CHUNK_SIZE) { + chunks.push(fileIds.slice(i, i + GET_FILE_CHUNK_SIZE)); + } + + // Get file infos for each chunk + const fileInfos = await Promise.all(chunks.map(getFilesInternal)); + return fileInfos.flat(); + } + +/** + * Get file infos for list of files given Ids + * @param fileIds list of file ids (smaller than 100) + * @returns list of file infos + */ +async function getFilesInternal(fileIds: number[]): Promise { const prefixPath = `/files/${getCurrentUser()!.uid}`; // IMPORTANT: if this isn't there, then a blank