Flush cache when reset db (#5214)
Now that we have persistent cache for schemas, we want to be able to reset its state when users run the database:reset db otherwise schemas won't be synced with the new DB state. Note: In an upcoming PR, we want to be able to invalidate the cache on a workspace level when we change the metadata schema through twenty version upgrade
This commit is contained in:
@ -11,7 +11,6 @@ import { seedCoreSchema } from 'src/database/typeorm-seeds/core';
|
|||||||
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
||||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||||
import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service';
|
import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service';
|
||||||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
|
||||||
import {
|
import {
|
||||||
SEED_APPLE_WORKSPACE_ID,
|
SEED_APPLE_WORKSPACE_ID,
|
||||||
SEED_TWENTY_WORKSPACE_ID,
|
SEED_TWENTY_WORKSPACE_ID,
|
||||||
@ -28,6 +27,9 @@ import { seedCalendarChannels } from 'src/database/typeorm-seeds/workspace/calen
|
|||||||
import { seedCalendarChannelEventAssociations } from 'src/database/typeorm-seeds/workspace/calendar-channel-event-association';
|
import { seedCalendarChannelEventAssociations } from 'src/database/typeorm-seeds/workspace/calendar-channel-event-association';
|
||||||
import { seedCalendarEventParticipants } from 'src/database/typeorm-seeds/workspace/calendar-event-participants';
|
import { seedCalendarEventParticipants } from 'src/database/typeorm-seeds/workspace/calendar-event-participants';
|
||||||
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
||||||
|
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
|
||||||
|
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
|
||||||
|
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
|
||||||
|
|
||||||
// TODO: implement dry-run
|
// TODO: implement dry-run
|
||||||
@Command({
|
@Command({
|
||||||
@ -39,12 +41,13 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
|||||||
workspaceIds = [SEED_APPLE_WORKSPACE_ID, SEED_TWENTY_WORKSPACE_ID];
|
workspaceIds = [SEED_APPLE_WORKSPACE_ID, SEED_TWENTY_WORKSPACE_ID];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly environmentService: EnvironmentService,
|
|
||||||
private readonly dataSourceService: DataSourceService,
|
private readonly dataSourceService: DataSourceService,
|
||||||
private readonly typeORMService: TypeORMService,
|
private readonly typeORMService: TypeORMService,
|
||||||
private readonly workspaceSyncMetadataService: WorkspaceSyncMetadataService,
|
private readonly workspaceSyncMetadataService: WorkspaceSyncMetadataService,
|
||||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||||
private readonly objectMetadataService: ObjectMetadataService,
|
private readonly objectMetadataService: ObjectMetadataService,
|
||||||
|
@InjectCacheStorage(CacheStorageNamespace.WorkspaceSchema)
|
||||||
|
private readonly workspaceSchemaCache: CacheStorageService,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -52,6 +55,8 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
|||||||
async run(): Promise<void> {
|
async run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
for (const workspaceId of this.workspaceIds) {
|
for (const workspaceId of this.workspaceIds) {
|
||||||
|
await this.workspaceSchemaCache.flush();
|
||||||
|
|
||||||
await rawDataSource.initialize();
|
await rawDataSource.initialize();
|
||||||
|
|
||||||
await seedCoreSchema(rawDataSource, workspaceId);
|
await seedCoreSchema(rawDataSource, workspaceId);
|
||||||
|
|||||||
@ -63,6 +63,10 @@ export class CacheStorageService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async flush() {
|
||||||
|
return this.cache.reset();
|
||||||
|
}
|
||||||
|
|
||||||
private isRedisCache() {
|
private isRedisCache() {
|
||||||
return (this.cache.store as any)?.name === 'redis';
|
return (this.cache.store as any)?.name === 'redis';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user