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

[🗄️ cache] Make ApolloStore.publish() suspend #5755

Merged
merged 2 commits into from
Mar 22, 2024
Merged

Conversation

martinbonnin
Copy link
Contributor

@martinbonnin martinbonnin commented Mar 21, 2024

Made publish suspend so that the cache writers wait for the readers and no cache key event is lost. The buffer of size 64 is still there to smooth things out.

Incubating cache gets removed publish parameter.
Stable cache gets overloads writeFoo() functions. The ones with a publish parameter should probably be deprecated but I'm not 100% sure yet.

Next steps:

  • benchmark thread hops vs no thread hops
  • make watch() return a FusibleFlow so that the user has control of the buffering there.
  • maybe deprecated ApolloStore.writeFoo(publish)

See #3920

@martinbonnin martinbonnin requested a review from BoD as a code owner March 21, 2024 18:57
Copy link

netlify bot commented Mar 21, 2024

Deploy Preview for apollo-android-docs canceled.

Name Link
🔨 Latest commit 50d6060
🔍 Latest deploy log https://app.netlify.com/sites/apollo-android-docs/deploys/65fd6ad91aed8e0008cd1dd8

Comment on lines +342 to +343
// Because subscribe is called from a background thread, give some time to be effective
delay(500)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting one. If we want a guarantee that .watch() subscribes synchronously, we probably need to go back to "interceptors do their own dispatcher switch". I want to measure how costly the thread switch is.

Copy link
Contributor

@BoD BoD left a comment

Choose a reason for hiding this comment

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

⚙️

Comment on lines 87 to 88
* Write an operation data to the store and optionally publish changes of [Record] which have changed,
* that will notify any watcher that depends on these [Record] to re-fetch.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Write an operation data to the store and optionally publish changes of [Record] which have changed,
* that will notify any watcher that depends on these [Record] to re-fetch.
* Write an operation data to the store.

Or maybe do we want to highlight it a bit more?

Suggested change
* Write an operation data to the store and optionally publish changes of [Record] which have changed,
* that will notify any watcher that depends on these [Record] to re-fetch.
* Write an operation data to the store. Call [publish] with the returned keys to notify any watcher that depends on these [Record] to re-fetch.

(same for writeFragment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call out. I added a @see publish tag so hopefully it should be enough.

@martinbonnin martinbonnin merged commit b54afc5 into main Mar 22, 2024
9 checks passed
@martinbonnin martinbonnin deleted the suspend-publish branch March 22, 2024 13:00
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