From c29f21ac56f464cfe05b04c44a3c666da5c8e717 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 6 Apr 2023 19:45:12 +0900 Subject: [PATCH] perf(backend): prevent emit needless db queries --- packages/backend/src/core/entities/DriveFileEntityService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/backend/src/core/entities/DriveFileEntityService.ts b/packages/backend/src/core/entities/DriveFileEntityService.ts index 2d40f444c..d82f36d97 100644 --- a/packages/backend/src/core/entities/DriveFileEntityService.ts +++ b/packages/backend/src/core/entities/DriveFileEntityService.ts @@ -266,6 +266,7 @@ export class DriveFileEntityService { fileIds: DriveFile['id'][], options?: PackOptions, ): Promise['id'], Packed<'DriveFile'> | null>> { + if (fileIds.length === 0) return new Map(); const files = await this.driveFilesRepository.findBy({ id: In(fileIds) }); const packedFiles = await this.packMany(files, options); const map = new Map['id'], Packed<'DriveFile'> | null>(packedFiles.map(f => [f.id, f])); @@ -280,6 +281,7 @@ export class DriveFileEntityService { fileIds: DriveFile['id'][], options?: PackOptions, ): Promise[]> { + if (fileIds.length === 0) return []; const filesMap = await this.packManyByIdsMap(fileIds, options); return fileIds.map(id => filesMap.get(id)).filter(isNotNull); }