Fix broken data model translation (#13067)
In this PR, I'm fixing a bug introduced in recent performance work on the cache. Bug context: https://github.com/twentyhq/twenty/issues/12865 Related PR opened by a contributor: https://github.com/twentyhq/twenty/pull/13003 ## Root cause We cache all objectMetadataItems at graphql level : see `useCachedMetadata` hook: - instead of going through the regular resolvers, we direlcty load data from the cache. However this data must be localized regarding labels and descriptions In a precedent refactoring, we introduced the notion of locale in the cache key. However, the user locale was not properly taken into account as we did not have the information in this hook. ## Fix 1. **Introduce locale in userWorkspace entity**. The locale is stored on workspaceMember in each postgres workspaceSchema (workspace_xxx) which is the alter ego of userWorkspace in postgres core schema. Note that we can't store it in user as a user can be part of multiple workspaces (the locale already there must be seen as a default for this user), and we cannot rely on workspaceMember as we would need to query the workspaceSchema in the authentication layer which we want to avoid for performance reasons. 2. During request hydration from token (containing the userWorkspaceId), we fetch the userWorkspace and store it in the Request (this impact both AuthContext and Request interface) 3. Leverage userWorkspace.locale in the useCachedMetadata hook ## Additional notes There is no need to change the way we store and retrieve the object-metadata-maps object itself which is different from the graphql layer cache. object-metadadata-maps are not localized
This commit is contained in:
@ -0,0 +1,19 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddLocaleToUserWorkspace1751700932529
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddLocaleToUserWorkspace1751700932529';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."userWorkspace" ADD "locale" character varying NOT NULL DEFAULT 'en'`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."userWorkspace" DROP COLUMN "locale"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user