Skip to content

Commit

Permalink
feat: clear the autoLoadEntities cache automatically on app shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Sep 23, 2023
1 parent cd25d2c commit aca7c01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/mikro-orm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions } from './ty
import { MikroOrmModuleOptions } from './typings';
import { MikroOrmMiddleware } from './mikro-orm.middleware';
import { forRoutesPath } from './middleware.helper';
import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage';

async function tryRequire(name: string): Promise<Dictionary | undefined> {
try {
Expand Down Expand Up @@ -111,6 +112,7 @@ export class MikroOrmCoreModule implements OnApplicationShutdown {

if (orm) {
await orm.close();
MikroOrmEntitiesStorage.clear(orm.config.get('contextName'));
}

CONTEXT_NAMES.length = 0;
Expand Down
7 changes: 1 addition & 6 deletions src/mikro-orm.entities.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ export class MikroOrmEntitiesStorage {
}

static clear(contextName = 'default') {
const set = this.storage.get(contextName);
if (!set) {
return;
}

set.clear();
this.storage.get(contextName)?.clear();
}

}

0 comments on commit aca7c01

Please sign in to comment.