Add fail on metadata cache miss (#7118)

- avoid failing when missing cache (used for command)
- remove unused load cache function. Cache will be always re-created
when trying to fetch if not existing
This commit is contained in:
Thomas Trompette
2024-09-18 15:40:24 +02:00
committed by GitHub
parent 44587b4908
commit 741a969cc1
5 changed files with 92 additions and 74 deletions

View File

@ -15,16 +15,19 @@ export class TwentyORMGlobalManager {
async getRepositoryForWorkspace<T extends ObjectLiteral>(
workspaceId: string,
workspaceEntity: Type<T>,
failOnMetadataCacheMiss?: boolean,
): Promise<WorkspaceRepository<T>>;
async getRepositoryForWorkspace<T extends ObjectLiteral>(
workspaceId: string,
objectMetadataName: string,
failOnMetadataCacheMiss?: boolean,
): Promise<WorkspaceRepository<T>>;
async getRepositoryForWorkspace<T extends ObjectLiteral>(
workspaceId: string,
workspaceEntityOrobjectMetadataName: Type<T> | string,
failOnMetadataCacheMiss = true,
): Promise<WorkspaceRepository<T>> {
let objectMetadataName: string;
@ -39,6 +42,7 @@ export class TwentyORMGlobalManager {
const workspaceDataSource = await this.workspaceDataSourceFactory.create(
workspaceId,
null,
failOnMetadataCacheMiss,
);
const repository = workspaceDataSource.getRepository<T>(objectMetadataName);
@ -50,11 +54,7 @@ export class TwentyORMGlobalManager {
return await this.workspaceDataSourceFactory.create(workspaceId, null);
}
async loadDataSourceForWorkspace(workspaceId: string) {
await this.workspaceDataSourceFactory.create(workspaceId, null);
}
async destroyDataSourceForWorkspace(workspaceId: string) {
await this.workspaceDataSourceFactory.destroy(workspaceId, null);
await this.workspaceDataSourceFactory.destroy(workspaceId);
}
}