Files
twenty/packages
Weiko 108cc5b6a5 API key creation triggers unnecessary ORMEntityMetadatas cache recomputation (#22168)
## Context

Creating an API key only changes role/apiKey-related data, but the
workspace migration runner was also invalidating and recomputing the
metadata caches (`ORMEntityMetadatas` and `graphQLResolverNameMap`) on
it.

The root cause is a single `if` block in
`getLegacyCacheInvalidationPromises` that gated **all** caches with an
`||` condition combining the metadata and role/permission conditions:

```ts
if (
  shouldIncrementMetadataGraphqlSchemaVersion ||
  shouldInvalidateRoleMapCache ||
  shouldInvalidateRolesPermissionsCache
) {
  // recomputes role caches AND ORMEntityMetadatas + graphQLResolverNameMap
}
```

So any role-only change (such as API key creation, which sets
`shouldInvalidateRoleMapCache`) also recomputed `ORMEntityMetadatas` —
an expensive recomputation that does not depend on role data.

## Fix

Split the combined block into two independent blocks, each gated by its
own condition:

- `shouldIncrementMetadataGraphqlSchemaVersion` → invalidate/recompute
only the metadata-derived caches: `ORMEntityMetadatas` and
`graphQLResolverNameMap`
- `shouldInvalidateRoleMapCache ||
shouldInvalidateRolesPermissionsCache` → invalidate/recompute only the
role/permissions caches

`graphQLResolverNameMap` is built from `flatObjectMetadataMaps` (see
`WorkspaceResolverNameMapCacheService`), so it is grouped with
`ORMEntityMetadatas` in the metadata block rather than the role block.

## Result

- Role-only changes (e.g. API key creation) no longer trigger
unnecessary `ORMEntityMetadatas` / `graphQLResolverNameMap`
recomputation.
- Metadata-only changes no longer recompute the role/permissions caches.
2026-06-25 13:53:58 +02:00
..