Refactor metadata caching (#7011)
This PR introduces the following changes: - add the metadataVersion to all our metadata cache keys to ease troubleshooting: <img width="1146" alt="image" src="https://github.com/user-attachments/assets/8427805b-e07f-465e-9e69-1403652c8b12"> - introduce a cache recompute lock to avoid overloading the database to recompute the cache many time
This commit is contained in:
committed by
Charles Bochet
parent
9b46e8c663
commit
3c4168759a
@ -1,11 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { EnvironmentModule } from 'src/engine/core-modules/environment/environment.module';
|
||||
import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module';
|
||||
import { DataSeedDemoWorkspaceService } from 'src/database/commands/data-seed-demo-workspace/services/data-seed-demo-workspace.service';
|
||||
import { EnvironmentModule } from 'src/engine/core-modules/environment/environment.module';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module';
|
||||
|
||||
@Module({
|
||||
imports: [WorkspaceManagerModule, EnvironmentModule],
|
||||
imports: [
|
||||
WorkspaceManagerModule,
|
||||
EnvironmentModule,
|
||||
TypeOrmModule.forFeature([Workspace], 'core'),
|
||||
],
|
||||
providers: [DataSeedDemoWorkspaceService],
|
||||
exports: [DataSeedDemoWorkspaceService],
|
||||
})
|
||||
|
||||
@ -1,18 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
import {
|
||||
deleteCoreSchema,
|
||||
seedCoreSchema,
|
||||
} from 'src/database/typeorm-seeds/core/demo';
|
||||
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
|
||||
@Injectable()
|
||||
export class DataSeedDemoWorkspaceService {
|
||||
constructor(
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly workspaceManagerService: WorkspaceManagerService,
|
||||
@InjectRepository(Workspace, 'core')
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
) {}
|
||||
|
||||
async seedDemo(): Promise<void> {
|
||||
@ -27,8 +33,14 @@ export class DataSeedDemoWorkspaceService {
|
||||
);
|
||||
}
|
||||
for (const workspaceId of demoWorkspaceIds) {
|
||||
await deleteCoreSchema(rawDataSource, workspaceId);
|
||||
await this.workspaceManagerService.delete(workspaceId);
|
||||
const existingWorkspaces = await this.workspaceRepository.findBy({
|
||||
id: workspaceId,
|
||||
});
|
||||
|
||||
if (existingWorkspaces.length > 0) {
|
||||
await this.workspaceManagerService.delete(workspaceId);
|
||||
await deleteCoreSchema(rawDataSource, workspaceId);
|
||||
}
|
||||
|
||||
await seedCoreSchema(rawDataSource, workspaceId);
|
||||
await this.workspaceManagerService.initDemo(workspaceId);
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
Workspace,
|
||||
WorkspaceActivationStatus,
|
||||
} from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceMetadataVersionService } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.service';
|
||||
import { WorkspaceMetadataVersionService } from 'src/engine/metadata-modules/workspace-metadata-version/services/workspace-metadata-version.service';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
|
||||
import { MessageChannelMessageAssociationWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity';
|
||||
|
||||
Reference in New Issue
Block a user