mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-08-03 04:44:06 +00:00
Load relations sequentially (#212)
This commit is contained in:
parent
2517f110ea
commit
be65ca45ea
@ -632,8 +632,9 @@ export class Database {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
const relationPromises = selections.filter((selection) => selection.kind === 'Field' && Boolean(relations[selection.name.value]))
|
const relationSelections = selections.filter((selection) => selection.kind === 'Field' && Boolean(relations[selection.name.value]));
|
||||||
.map(async selection => {
|
|
||||||
|
for (const selection of relationSelections) {
|
||||||
assert(selection.kind === 'Field');
|
assert(selection.kind === 'Field');
|
||||||
const field = selection.name.value;
|
const field = selection.name.value;
|
||||||
const { entity: relationEntity, isArray, isDerived, field: foreignKey } = relations[field];
|
const { entity: relationEntity, isArray, isDerived, field: foreignKey } = relations[field];
|
||||||
@ -684,7 +685,7 @@ export class Database {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
@ -728,7 +729,7 @@ export class Database {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// field is neither an array nor derivedFrom
|
// field is neither an array nor derivedFrom
|
||||||
@ -738,7 +739,7 @@ export class Database {
|
|||||||
entity[field] = { id: entity[field] };
|
entity[field] = { id: entity[field] };
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const where: Where = {
|
const where: Where = {
|
||||||
@ -770,9 +771,7 @@ export class Database {
|
|||||||
entity[field] = relatedEntitiesMap[entity[field]];
|
entity[field] = relatedEntitiesMap[entity[field]];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
await Promise.all(relationPromises);
|
|
||||||
|
|
||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user