From 3874b58d5347389823f83e0d1956836e1d97f0be Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Thu, 5 Mar 2026 08:37:06 +0000 Subject: [PATCH] Uncached workspace entity DB lookup causes 2.7s auth overhead per request https://sonarly.com/issue/3773?type=bug The JWT auth strategy loads the WorkspaceEntity from the database on every authenticated request without caching, causing a 2774ms primary key lookup on this resource-constrained self-hosted instance and resulting in 3.5s total response time for a simple aggregate query. --- .../services/workspace-migration-runner.service.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts index 4a0b758a787..9ec4d8cd388 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts @@ -85,21 +85,17 @@ export class WorkspaceMigrationRunnerService { flatMapsKeysSet.has('flatRoleMaps') || flatMapsKeysSet.has('flatRoleTargetMaps'); - if (shouldIncrementMetadataGraphqlSchemaVersion) { - asyncOperations.push( - this.workspaceCacheService.invalidateAndRecompute(workspaceId, [ - 'ORMEntityMetadatas', - ]), - ); - } - - if (shouldInvalidateRoleMapCache) { + if ( + shouldIncrementMetadataGraphqlSchemaVersion || + shouldInvalidateRoleMapCache + ) { asyncOperations.push( this.workspaceCacheService.invalidateAndRecompute(workspaceId, [ 'rolesPermissions', 'userWorkspaceRoleMap', 'flatRoleTargetMaps', 'apiKeyRoleMap', + 'ORMEntityMetadatas', 'flatRoleTargetByAgentIdMaps', ]), );