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

Stop treating dangling references differently from empty objects. #6365

Merged
merged 1 commit into from
May 30, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented May 29, 2020

Question: When cache.read{Query,Fragment} encounters a dangling reference (one that does not currently refer to any normalized entity object in the cache), should the cache behave as if the (nonexistent) target of the reference was an empty object, and report any requested fields as missing, or should the cache generate some other kind of error that reflects the the absence of the whole object?

I think we could answer this question either way, but I'm leaning towards the first option.

Note: it's normal for the cache to end up with dangling references when whole entity objects are evicted, or when a reference is created (e.g. by toReference in a read function) without writing any data into the cache. Cleaning up dangling references is a tricky problem, requiring application-level reasoning—and not even always desirable, since the data could always come back into the cache later, restoring the validity of the reference.

Previously, I thought it would be helpful to distinguish between the absence of an entity object and the object simply being empty, but I no longer think this distinction (which only affected the wording of the MissingFieldError description) matters very much, and we can simplify everything by adopting the following policy:

During cache reads, a dangling Reference should behave as much as possible like a Reference to an entity object that happens to contain zero fields.

I'm optimistic this policy may help with issues like #6325. At the very least, it means there's now only one flavor of MissingFieldError, which should reduce confusion.

Question: When cache.read{Query,Fragment} encounters a dangling reference
(one that does not currently refer to any normalized entity object in the
cache), should the cache behave as if the (nonexistent) target of the
reference was an empty object, and report any requested fields as missing,
or should the cache generate some other kind of error that reflects the
the absence of the whole object?

I think we could answer this question either way, but I'm leaning towards
the first option.

Note: it's normal for the cache to end up with dangling references when
whole entity objects are evicted, or when a reference is created (e.g. by
toReference) without writing any data into the cache. Cleaning up dangling
references is a tricky problem, requiring application-level reasoning, and
not even always desirable, since the data could always come back into the
cache later, restoring the validity of the reference.

Previously, I thought it would be helpful to distinguish between the
absence of an entity object and the object simply being empty, but I no
longer think this distinction (which only affected the wording of the
MissingFieldError description) matters very much, and we can simplify
everything by adopting the following policy:

> During cache reads, a dangling Reference should behave as much as
  possible like a Reference to an entity object that happens to contain
  zero fields.

I'm optimistic this policy may help with issues like #6325. At the very
least, this policy means there's now only one kind of MissingFieldError,
which should reduce confusion.
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

I like this approach as well @benjamn - thanks!

@benjamn benjamn merged commit c810713 into master May 30, 2020
@benjamn benjamn deleted the assume-dangling-references-refer-to-empty-objects branch May 30, 2020 00:07
benjamn added a commit that referenced this pull request Jun 1, 2020
…cts"

This reverts commit c810713, introduced
recently in PR #6365. My optimism that #6365 was an improvement seems to
have been misplaced, since it caused the regression reported in #6368.
We're too close to the AC3 RC/release to be floating risky changes like
these without compelling justifications.
@benjamn benjamn mentioned this pull request Jun 1, 2020
benjamn added a commit that referenced this pull request Jun 1, 2020
…cts" (#6371)

This reverts commit c810713, introduced
recently in PR #6365. My optimism that #6365 was an improvement seems to
have been misplaced, since it caused the regression reported in #6368.
We're too close to the AC3 RC/release to be floating risky changes like
these without compelling justifications.
benjamn added a commit that referenced this pull request Jul 27, 2020
PR #6353 explains the rationale for switching to a cache-first FetchPolicy
after an initial cache-and-network or network-only policy.

When #6365 was implemented, options.fetchPolicy was examined only once, at
the beginning of fetchQueryObservable, so the timing of changing
options.fetchPolicy did not matter as much. However, fixing #6659 involves
checking the current options.fetchPolicy whenever the QueryData class
calls this.currentObservable.getCurrentResult(), so it's now more
important to delay changing options.fetchPolicy until after the first
network request has completed.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants