Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential optimization - bail out of executeSubSelectedArray calls #11670

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-singers-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Bail out of `executeSubSelectedArray` calls if the array has 0 elements.
21 changes: 12 additions & 9 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,18 @@ export class StoreReader {
});
}
} else if (isArray(fieldValue)) {
fieldValue = handleMissing(
this.executeSubSelectedArray({
field: selection,
array: fieldValue,
enclosingRef,
context,
}),
resultName
);
fieldValue =
fieldValue.length === 0 ?
fieldValue
: handleMissing(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably rearrange this so it only calls handleMissing and updates fieldValue if fieldValue.length > 0, but I leave that 🏌️ up to you.

this.executeSubSelectedArray({
field: selection,
array: fieldValue,
enclosingRef,
context,
}),
resultName
);
} else if (!selection.selectionSet) {
// If the field does not have a selection set, then we handle it
// as a scalar value. To keep this.canon from canonicalizing
Expand Down
Loading