From bce83c52f0d0620dc46e127f06abede7c05c30b7 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Mon, 13 Oct 2025 16:09:10 +0200 Subject: [PATCH] Increment metadata version only if schema changes v2 (#15064) # Introduction After updating a `viewField` in a view the frontend receives a missmatch metadata version. That's because the `flatFieldMetadata` needs to be invalidated on a viewField addition as it contains its primary key in its cache. Before we would be checking updated flat entity maps, meaning that on a view field update the flat field metadata maps would also get updated, but we also invalidate the old v1 cache at the same time. Resuling in a metadata version missmatch that's not really relevant for the gql schema integrity Now we only check if a object or field actions has been processed, if yes increment the metadata version. We should deco-relate the v1 object and fields cache from the metadata version that should only serve as a "Please refresh browser state because gql schema has mutated" --- .../workspace-migration-runner-v2.service.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-v2/workspace-migration-runner-v2/services/workspace-migration-runner-v2.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-v2/workspace-migration-runner-v2/services/workspace-migration-runner-v2.service.ts index 723abd88fa..169d6770f6 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-v2/workspace-migration-runner-v2/services/workspace-migration-runner-v2.service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-v2/workspace-migration-runner-v2/services/workspace-migration-runner-v2.service.ts @@ -97,11 +97,25 @@ export class WorkspaceMigrationRunnerV2Service { 'Runner', `Cache invalidation ${flatEntitiesCacheToInvalidate.join()}`, ); - if ( - flatEntitiesCacheToInvalidate.includes('flatObjectMetadataMaps') || - flatEntitiesCacheToInvalidate.includes('flatFieldMetadataMaps') - ) { - // Temporarily invalidation old cache too until it's deprecated + const shouldIncrementMetadataGraphqlSchemaVersion = actions.some( + (action) => { + switch (action.type) { + case 'delete_field': + case 'create_field': + case 'update_field': + case 'delete_object': + case 'create_object': + case 'update_object': { + return true; + } + default: { + return false; + } + } + }, + ); + + if (shouldIncrementMetadataGraphqlSchemaVersion) { await this.workspaceMetadataVersionService.incrementMetadataVersion( workspaceId, );