From faf3b6c2358c22fffa4a082d314705568edf7004 Mon Sep 17 00:00:00 2001 From: Kristiyan Tachev Date: Tue, 23 Apr 2024 13:13:31 +0300 Subject: [PATCH] feat(cache): database connection cache --- src/injection.tokens.ts | 1 + src/services/migration/migration.service.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/injection.tokens.ts b/src/injection.tokens.ts index 434419d..7b66168 100644 --- a/src/injection.tokens.ts +++ b/src/injection.tokens.ts @@ -36,6 +36,7 @@ export interface BundlerConfig { export interface Config { database: { + _connection_cache?: MongoClient; connect?(): Promise; }; dateTimeFormat?: () => string; diff --git a/src/services/migration/migration.service.ts b/src/services/migration/migration.service.ts index ffcecc6..de0fa0b 100644 --- a/src/services/migration/migration.service.ts +++ b/src/services/migration/migration.service.ts @@ -22,7 +22,13 @@ export class MigrationService { ) {} async connect() { - return this.configService.config.database.connect(); + if (this.configService.config.database._connection_cache) { + return this.configService.config.database._connection_cache; + } + + this.configService.config.database._connection_cache = await this.configService.config.database.connect(); + + return this.configService.config.database._connection_cache; } async up() {