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

Prevent @client @export from firing unnecessary network requests #5946

Merged
merged 1 commit into from
Feb 15, 2020

Conversation

hwillson
Copy link
Member

PR #4604 fixed an issue where changes made to @client @export based variables didn't always result in re-running the query that was using the variable. Unfortunately, these changes are a bit too aggressive. They're triggering a refetch when an @client @export based variable changes (and a few additional conditions are met), and while using the ObservableQuery.refetch() method does fix the original issue, it leads to a situation where the query being re-run is always fired over the network, even if the updated query could have been resolved from the cache. ObservableQuery.refetch() forces queries to use a network based fetch policy, which means if the query was originally fired with a cache-first policy (for example), and has matching data in the cache after taking into consideration the new variable, that data won't be used and instead an extra unnecessary network request will fire.

This commit addresses the issue by leveraging ObservableQuery.setVariables() instead of automatically refetching. setVariables will attempt to resolve the updated query from the cache first, then only fire it over the network if required.

@hwillson hwillson force-pushed the prevent-extra-client-export-requests branch 3 times, most recently from f2783bd to d6d4641 Compare February 14, 2020 19:48
@hwillson hwillson self-assigned this Feb 14, 2020
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Looks good to me, with one small opportunity to save some bytes.

src/core/ObservableQuery.ts Outdated Show resolved Hide resolved
@benjamn benjamn added this to the Release 3.0 milestone Feb 14, 2020
PR #4604 fixed an
issue where changes made to `@client @export` based variables didn't
always result in re-running the query that was using the variable.
Unfortunately, these changes are a bit too aggressive. They're
triggering a `refetch` when an `@client @export` based variable
changes (and a few additional conditions are met), and while using
the `ObservableQuery.refetch()` method does fix the original issue,
it leads to a situation where the query being re-run is always fired
over the network, even if the updated query could have been resolved
from the cache. `ObservableQuery.refetch()` forces queries to use a
network based fetch policy, which means if the query was originally
fired with a `cache-first` policy (for example), and has matching
data in the cache after taking into consideration the new variable,
that data won't be used and instead an extra unnecessary network
request will fire.

This commit addresses the issue by leveraging
`ObservableQuery.setVariables()` instead of automatically
refetching. `setVariables` will attempt to resolve the updated
query from the cache first, then only fire it over the network if
required.
@hwillson hwillson force-pushed the prevent-extra-client-export-requests branch from d6d4641 to 86a1b25 Compare February 15, 2020 18:30
@hwillson hwillson merged commit 7cbfcf7 into master Feb 15, 2020
@hwillson hwillson deleted the prevent-extra-client-export-requests branch February 15, 2020 18:42
hwillson added a commit that referenced this pull request Feb 23, 2020
The changes made in #5946 helped address an issue where queries
with `@client @export` variables were making unnecessary
network requests. While those changes work, they're currently
preventing watched queries using `@client @export` from updating
the `@export`ed variable, as new data is received. This commit
fixes that issue.
hwillson added a commit that referenced this pull request Feb 23, 2020
The changes made in #5946 helped address an issue where queries
with `@client @export` variables were making unnecessary
network requests. While those changes work, they're currently
preventing watched queries using `@client @export` from updating
the `@export`ed variable, as new data is received. This commit
fixes that issue.
hwillson added a commit that referenced this pull request Feb 24, 2020
The changes made in #5946 helped address an issue where queries
with `@client @export` variables were making unnecessary
network requests. While those changes work, they're currently
preventing watched queries using `@client @export` from updating
the `@export`ed variable, as new data is received. This commit
fixes that issue.
hwillson added a commit that referenced this pull request Feb 25, 2020
The changes made in #5946 helped address an issue where queries
with `@client @export` variables were making unnecessary
network requests. While those changes work, they're currently
preventing watched queries using `@client @export` from updating
the `@export`ed variable, as new data is received. This commit
fixes that issue.
@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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants