diff --git a/packages/apollo-collaboration-server/src/files/files.service.ts b/packages/apollo-collaboration-server/src/files/files.service.ts index d52cc7e9..571341c6 100644 --- a/packages/apollo-collaboration-server/src/files/files.service.ts +++ b/packages/apollo-collaboration-server/src/files/files.service.ts @@ -84,6 +84,8 @@ export class FilesService { return fileStream.pipe(gunzip) } + private fileHandleCache: Record = {} + getFileHandle(file: FileDocument): GenericFilehandle { const fileUploadFolder = this.configService.get('FILE_UPLOAD_FOLDER', { infer: true, @@ -92,7 +94,13 @@ export class FilesService { switch (file.type) { case 'text/x-fai': case 'application/x-gzi': { - return new LocalFileGzip(fileName) + const fileHandleCacheHit = this.fileHandleCache[fileName] + if (fileHandleCacheHit) { + return fileHandleCacheHit + } + const fh = new LocalFileGzip(fileName) + this.fileHandleCache[fileName] = fh + return fh } case 'application/x-bgzip-fasta': case 'text/x-gff3':