Flat entity maps cache generic service + runner dynamically retrieving invalidating update cache + view service v2 refactor (#14508)

# Introduction
Migrate previous runner only iterating on `flatObjectMetadataMaps` to
`allFlatEntityMaps`.
Refactored the optimistic to be handled inside the actions handler

## Workspace flat map cache
Introducing a new service and registry, that will dynamically retrieve
and or recompute requested cache when called

## Runner refactor
Runner now dynamically invalidate updated cache at the end of the
transaction

close
https://github.com/orgs/twentyhq/projects/1/views/8?pane=issue&itemId=129136356&issue=twentyhq%7Ccore-team-issues%7C1492
close
https://github.com/orgs/twentyhq/projects/1/views/8?pane=issue&itemId=129136210&issue=twentyhq%7Ccore-team-issues%7C1494
This commit is contained in:
Paul Rastoin
2025-09-16 14:39:42 +02:00
committed by GitHub
parent 8f42c33bd4
commit 371c26bc9b
79 changed files with 1534 additions and 575 deletions
@@ -3,4 +3,5 @@ import { type FlatObjectMetadataMaps } from 'src/engine/metadata-modules/flat-ob
export const EMPTY_FLAT_OBJECT_METADATA_MAPS = {
byId: {},
idByNameSingular: {},
idByUniversalIdentifier: {},
} as const satisfies FlatObjectMetadataMaps;
@@ -3,4 +3,5 @@ import { type FlatObjectMetadataWithFlatFieldMaps } from 'src/engine/metadata-mo
export type FlatObjectMetadataMaps = {
byId: Partial<Record<string, FlatObjectMetadataWithFlatFieldMaps>>;
idByNameSingular: Partial<Record<string, string>>;
idByUniversalIdentifier: Record<string, string>;
};
@@ -27,6 +27,9 @@ export const addFlatFieldMetadataInFlatObjectMetadataMapsOrThrow = ({
}
return {
idByUniversalIdentifier: {
...flatObjectMetadataMaps.idByUniversalIdentifier,
},
byId: {
...flatObjectMetadataMaps.byId,
[flatFieldMetadata.objectMetadataId]:
@@ -24,6 +24,10 @@ export const addFlatObjectMetadataToFlatObjectMetadataMapsOrThrow = ({
}
return {
idByUniversalIdentifier: {
...flatObjectMetadataMaps.idByUniversalIdentifier,
[flatObjectMetadata.universalIdentifier]: flatObjectMetadata.id,
},
byId: {
...flatObjectMetadataMaps.byId,
[flatObjectMetadata.id]:
@@ -29,6 +29,11 @@ export const addFlatObjectMetadataWithFlatFieldMapsToFlatObjectMetadataMapsOrThr
}
return {
idByUniversalIdentifier: {
...flatObjectMetadataMaps.idByUniversalIdentifier,
[flatObjectMetadataWithFlatFieldMaps.universalIdentifier]:
flatObjectMetadataWithFlatFieldMaps.id,
},
byId: {
...flatObjectMetadataMaps.byId,
[flatObjectMetadataWithFlatFieldMaps.id]:
@@ -28,6 +28,7 @@ export const deleteFieldFromFlatObjectMetadataMapsOrThrow = ({
}
return {
idByUniversalIdentifier: flatObjectMetadataMaps.idByUniversalIdentifier,
byId: {
...flatObjectMetadataMaps.byId,
[objectMetadataId]:
@@ -25,7 +25,14 @@ export const deleteObjectFromFlatObjectMetadataMapsOrThrow = ({
flatObjectMetadataMaps.idByNameSingular,
).filter(([_nameSingular, id]) => id !== objectMetadataId);
const updatedIdByUniversalIdentifierEntries = Object.entries(
flatObjectMetadataMaps.idByUniversalIdentifier,
).filter(([_universalIdentifier, id]) => id !== objectMetadataId);
return {
idByUniversalIdentifier: Object.fromEntries(
updatedIdByUniversalIdentifierEntries,
),
byId: removePropertiesFromRecord(flatObjectMetadataMaps.byId, [
objectMetadataId,
]),
@@ -24,6 +24,15 @@ export const fromObjectMetadataMapsToFlatObjectMetadataMaps = (
}, initialAccumulator);
return {
idByUniversalIdentifier: Object.values(objectMetadataMaps.byId)
.filter(isDefined)
.reduce(
(acc, objectMetadata) => ({
...acc,
[objectMetadata.standardId ?? objectMetadata.id]: objectMetadata.id,
}),
{},
),
idByNameSingular: objectMetadataMaps.idByNameSingular,
byId,
};