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

Include watch.callback in maybeBroadcastWatch cache keys. #5747

Merged

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jan 3, 2020

Fixes #5733, which was caused by multiple watches having the same cache key, so none except the first were ever re-broadcast, since the first broadcast had the side effect of marking the later watches as clean, before this.watches.forEach had a chance to visit them.

Background: PR #5644 reenabled an important optimization for the InMemoryCache#broadcastWatches method, allowing it to skip watches whose results have not changed. Unfortunately, while this optimization correctly determined whether the result had changed, it did not account for the possibility of multiple distinct consumers of the same result, which can happen (for example) when multiple components use the same query and variables via different useQuery calls.

Fortunately, the fix is straightforward (if not exactly obvious): in order to assign distinct consumers different cache keys, it suffices to include the provided watch.callback function in the cache key.

A more drastic way to fix #5733 would be to remove the caching of maybeBroadcastWatch entirely, which would not be a huge loss because the underlying cache.diff method is also cached. For now, though, with that backup option in mind, I'd like to preserve this optimization unless it causes any further problems.

Fixes #5733, which was caused by multiple watches having the same cache
key, so none except the first were ever re-broadcast, since the first
broadcast had the side effect of marking the later watches as clean,
before this.watches.forEach had a chance to visit them.

Background: PR #5644 reenabled an important optimization for the
InMemoryCache#broadcastWatches method, allowing it to skip watches whose
results have not changed. Unfortunately, while this optimization correctly
determined whether the result had changed, it did not account for the
possibility of multiple distinct consumers of the same result, which can
happen (for example) when multiple components use the same query and
variables via different useQuery calls.

Fortunately, the fix is straightforward (if not exactly obvious): in order
to assign distinct consumers different cache keys, it suffices to include
the provided watch.callback function in the cache key.

A more drastic way to fix #5733 would be to remove the caching of
maybeBroadcastWatch entirely, which would not be a huge loss because the
underlying cache.diff method is also cached. For now, though, with that
backup option in mind, I'd like to preserve this optimization unless it
causes any further problems.
@benjamn benjamn force-pushed the issue-5733-segment-maybeBroadcastWatch-by-callback branch from 16405a6 to 1c57170 Compare January 3, 2020 18:22
@benjamn benjamn merged commit 088d485 into release-3.0 Jan 3, 2020
@benjamn benjamn deleted the issue-5733-segment-maybeBroadcastWatch-by-callback branch January 3, 2020 18:35
@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.

None yet

1 participant