Skip to content

Commit

Permalink
feat(cache): database connection cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Stradivario committed Apr 23, 2024
1 parent 4e9bcb3 commit faf3b6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/injection.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface BundlerConfig {

export interface Config {
database: {
_connection_cache?: MongoClient;
connect?(): Promise<MongoClient>;
};
dateTimeFormat?: () => string;
Expand Down
8 changes: 7 additions & 1 deletion src/services/migration/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit faf3b6c

Please sign in to comment.