Browse Source

perf(core): Improve hydrator performance for customFields (#2961)

Remove a workaround that led to refetching relations in customFields.
Prevent refetching of customFields during hydration
Jonas Osburg 1 year ago
parent
commit
f40761d988

+ 6 - 1
packages/core/src/service/helpers/entity-hydrator/entity-hydrator.service.ts

@@ -200,11 +200,16 @@ export class EntityHydrator {
         const missingRelations: string[] = [];
         for (const relation of options.relations.slice().sort()) {
             if (typeof relation === 'string') {
-                const parts = !relation.startsWith('customFields') ? relation.split('.') : [relation];
+                const parts = relation.split('.');
                 let entity: Record<string, any> | undefined = target;
                 const path = [];
                 for (const part of parts) {
                     path.push(part);
+                    // null = the relation has been fetched but was null in the database.
+                    // undefined = the relation has not been fetched.
+                    if (entity && entity[part] === null) {
+                        break;
+                    }
                     if (entity && entity[part]) {
                         entity = Array.isArray(entity[part]) ? entity[part][0] : entity[part];
                     } else {