Skip to content

Commit

Permalink
avoid unnecessary fetch of related resources that are not included
Browse files Browse the repository at this point in the history
  • Loading branch information
mathematikoi authored Feb 9, 2024
1 parent 9b316af commit 7093085
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils/serializer.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ export async function recurseRelators(
?.some((i) => i.hasMore)) ??
false;

const resource = await relator.getRelatedResource(
cache[i],
undefined,
undefined,
// Only build the cache for the next iteration if needed.
shouldBuildRelatedCache ? newRelatorDataCache : undefined
);


// Include if,
// - includeFields !== undefined
// - includeFields has entry where field = relatedName
if (!includeFields || includeFields.map((i) => i.field).includes(relator.relatedName)) {
const resource = await relator.getRelatedResource(
cache[i],
undefined,
undefined,
// Only build the cache for the next iteration if needed.
shouldBuildRelatedCache ? newRelatorDataCache : undefined
);

const key = resource.getKey();
if (!keys.includes(key)) {
keys.push(key);
Expand Down

0 comments on commit 7093085

Please sign in to comment.