Skip to content

Commit

Permalink
Add cache to getFileHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Oct 10, 2024
1 parent c3c59b7 commit a9a9b25
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/apollo-collaboration-server/src/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class FilesService {
return fileStream.pipe(gunzip)
}

private fileHandleCache: Record<string, GenericFilehandle | undefined> = {}

getFileHandle(file: FileDocument): GenericFilehandle {
const fileUploadFolder = this.configService.get('FILE_UPLOAD_FOLDER', {
infer: true,
Expand All @@ -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':
Expand Down

0 comments on commit a9a9b25

Please sign in to comment.