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:
+1
@@ -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;
|
||||
|
||||
+1
@@ -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>;
|
||||
};
|
||||
|
||||
+3
@@ -27,6 +27,9 @@ export const addFlatFieldMetadataInFlatObjectMetadataMapsOrThrow = ({
|
||||
}
|
||||
|
||||
return {
|
||||
idByUniversalIdentifier: {
|
||||
...flatObjectMetadataMaps.idByUniversalIdentifier,
|
||||
},
|
||||
byId: {
|
||||
...flatObjectMetadataMaps.byId,
|
||||
[flatFieldMetadata.objectMetadataId]:
|
||||
|
||||
+4
@@ -24,6 +24,10 @@ export const addFlatObjectMetadataToFlatObjectMetadataMapsOrThrow = ({
|
||||
}
|
||||
|
||||
return {
|
||||
idByUniversalIdentifier: {
|
||||
...flatObjectMetadataMaps.idByUniversalIdentifier,
|
||||
[flatObjectMetadata.universalIdentifier]: flatObjectMetadata.id,
|
||||
},
|
||||
byId: {
|
||||
...flatObjectMetadataMaps.byId,
|
||||
[flatObjectMetadata.id]:
|
||||
|
||||
+5
@@ -29,6 +29,11 @@ export const addFlatObjectMetadataWithFlatFieldMapsToFlatObjectMetadataMapsOrThr
|
||||
}
|
||||
|
||||
return {
|
||||
idByUniversalIdentifier: {
|
||||
...flatObjectMetadataMaps.idByUniversalIdentifier,
|
||||
[flatObjectMetadataWithFlatFieldMaps.universalIdentifier]:
|
||||
flatObjectMetadataWithFlatFieldMaps.id,
|
||||
},
|
||||
byId: {
|
||||
...flatObjectMetadataMaps.byId,
|
||||
[flatObjectMetadataWithFlatFieldMaps.id]:
|
||||
|
||||
+1
@@ -28,6 +28,7 @@ export const deleteFieldFromFlatObjectMetadataMapsOrThrow = ({
|
||||
}
|
||||
|
||||
return {
|
||||
idByUniversalIdentifier: flatObjectMetadataMaps.idByUniversalIdentifier,
|
||||
byId: {
|
||||
...flatObjectMetadataMaps.byId,
|
||||
[objectMetadataId]:
|
||||
|
||||
+7
@@ -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,
|
||||
]),
|
||||
|
||||
+9
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user