From b1d9314d6ef7ff58698a1589d5c6e09b08b89801 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Wed, 16 Oct 2024 11:54:06 -0400 Subject: [PATCH] pre-create the `files` directory to reduce IO operations --- packages/backend/src/core/InternalStorageService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/InternalStorageService.ts b/packages/backend/src/core/InternalStorageService.ts index 02a0a745d6..7d2ea6ba20 100644 --- a/packages/backend/src/core/InternalStorageService.ts +++ b/packages/backend/src/core/InternalStorageService.ts @@ -24,6 +24,8 @@ export class InternalStorageService { @Inject(DI.config) private config: Config, ) { + // No one should erase the working directly *while the server is running*. + fs.mkdirSync(path, { recursive: true }); } @bindThis @@ -38,14 +40,12 @@ export class InternalStorageService { @bindThis public async saveFromPath(key: string, srcPath: string): Promise { - await mkdir(path, { recursive: true }); await copyFile(srcPath, this.resolvePath(key)); return `${this.config.url}/files/${key}`; } @bindThis public async saveFromBuffer(key: string, data: Buffer): Promise { - await mkdir(path, { recursive: true }); await writeFile(this.resolvePath(key), data); return `${this.config.url}/files/${key}`; }