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

(core) - Avoid dispatching an operation for already active cache-first/only operations #1600

Merged
merged 3 commits into from
May 3, 2021

Conversation

kitten
Copy link
Member

@kitten kitten commented May 2, 2021

Summary

Previously, in #1515 we merged the groundwork for making identical operations that are run concurrently more intuitive. Namely, when an active source is active multiple times then the sources that newly become active will have the last known result replayed. (There was one bug in there that's fixed in here; See "Set of changes")

We can use the same principle to make concurrent operations in general more intuitive. While it'd seem to make sense to create some kind of "result cache" that prevents unnecessary work, we now have the foundation that we need to make this intuitive and seamless, on top of existing logic.

With these changes applied we will now not dispatch a new operation on the Client and instead use the replayed result when the request policy isn't network-only or cache-and-network (since these intuitively instruct the cache to fetch). Instead when cache-first or cache-only are used and a replay result exists, the Client will only issue the replayed result and will not do anything else.

Set of changes

  • Fix an issue where a reused (but previously unsubscribed from) replayOnStart source wouldn't reset the replay value to undefined.
  • Create a 'pre' | 'post' mode for replayOnStart where 'pre' is the existing behaviour and 'post' issues the start() if no replay result is available
  • Update tests to account for the new difference

@changeset-bot
Copy link

changeset-bot bot commented May 2, 2021

🦋 Changeset detected

Latest commit: b6a6cea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten requested a review from JoviDeCroock May 2, 2021 21:57
@kitten kitten changed the title Feat/prevent unnecessary work (core) - Avoid dispatching an operation for already active cache-first/only operations May 2, 2021
@kitten kitten merged commit f02178f into main May 3, 2021
@kitten kitten deleted the feat/prevent-unnecessary-work branch May 3, 2021 10:30
@github-actions github-actions bot mentioned this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants