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

Move serialization outside of cache lock #5101

Merged
merged 3 commits into from
Jul 21, 2023
Merged

Conversation

ashare80
Copy link
Contributor

Lock blocks reads and writes during processing of data before and after accessing cache unnecessarily.

@apollo-cla
Copy link

@ashare80: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@netlify
Copy link

netlify bot commented Jul 18, 2023

👷 Deploy request for apollo-android-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e33a799

import com.apollographql.apollo3.api.json.MapJsonReader
import com.apollographql.apollo3.cache.normalized.api.CacheKey

data class CacheDataTransformer<D: Executable.Data>(
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
data class CacheDataTransformer<D: Executable.Data>(
internal class CacheDataTransformer<D: Executable.Data>(

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

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

One minor suggestion, LGTM otherwise, Thanks for the contribution!

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.

👍 Thanks!

@BoD
Copy link
Contributor

BoD commented Jul 19, 2023

I missed this before but indeed CacheDataTransformer cannot be internal because now fun <D : Executable.Data> Executable<D>.readDataFromCache() returns it (not caught at build time because we don't track the api in the incubating module).

To keep the return type of readDataFromCache we could:

  • add .toData(customScalarAdapters)
  • use readInternal instead of readDataFromCache inside readDataFromCacheInternal (it would have to be @ApolloInternal instead of private then)

@ashare80 ashare80 force-pushed the cache-lock branch 3 times, most recently from faf20d8 to 946c7d2 Compare July 19, 2023 21:40
@martinbonnin
Copy link
Contributor

martinbonnin commented Jul 20, 2023

Thanks again for the contribution! @BoD @ashare80, I pushed a few changes to:

  • keep non incubating artifacts in sync
  • keep backward compat and use @ApolloInternal to make the symbols we don't want to expose harder to use.

All in all, I think the Executable.readDataFromCache shouldn't have been part of the public API because they're not locking the store. Something to revisit before shipping v4.

Let me know what you think.

@ashare80
Copy link
Contributor Author

@martinbonnin Awesome thanks!

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.

This looks good to me 👍

@BoD BoD merged commit 6a06344 into apollographql:main Jul 21, 2023
4 checks passed
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.

4 participants