Example of aggressive API cache as well as operation order issue#1249
Closed
taquitos wants to merge 1 commit into
Closed
Example of aggressive API cache as well as operation order issue#1249taquitos wants to merge 1 commit into
taquitos wants to merge 1 commit into
Conversation
69a8c30 to
0e0448d
Compare
0e0448d to
3b304ad
Compare
Member
|
Yessssss! This successfully failed 🙌 |
Contributor
|
Fixed in #1292. |
NachoSoto
added a commit
that referenced
this pull request
Feb 15, 2022
Fixes [sc-12802]. Before this change, the sequence illustrated by the new test `testGetsUpdatedSubscriberInfoAfterPost` (started in #1249, with a few modifications here) would fail: - GET /subscribers/ - POST /receipts - GET /subscribers/ However, when the first GET request finished, the second one shared the cache key, so it received the (soon to be) outdated `CustomerInfo`. Unfortunately this fix is isolated for this specific issue, and not a generalized one. A more comprehensive rewrite of `HTTPClient` is needed ([sc-9521]). I came up with several other alternatives, but what I ended up going with here involves the least amount of moving pieces. If a `GetCustomerInfoOperation` request is enqueued with `PostReceiptDataOperation` in the queue, then a new unique cache key is created to avoid past `GetCustomerInfoOperation` to share outdata data. If we simply added a random number to the `GetCustomerInfoOperation` cache key, the new test would have also passed. No other test verified the caching behavior, which is what the new `testGetSubscriberInfoDoesNotMakeTwoRequests` checks.
NachoSoto
added a commit
that referenced
this pull request
Feb 15, 2022
Fixes [sc-12802]. ## Background Before this change, the sequence illustrated by the new test `testGetsUpdatedSubscriberInfoAfterPost` (started in #1249, with a few modifications here) would fail: - GET /subscribers/ - POST /receipts - GET /subscribers/ #1261 fixed the race condition in the test, making it so that operations are actually run serially. However, when the first GET request finished, the second one shared the cache key, so it received the (soon to be) outdated `CustomerInfo`. ## The fix Unfortunately this fix is isolated for this specific issue, and not a generalized one. A more comprehensive rewrite of `HTTPClient` is needed ([sc-9521]). I came up with several other alternatives, but what I ended up going with here involves the least amount of moving pieces. If a `GetCustomerInfoOperation` request is enqueued with `PostReceiptDataOperation` in the queue, then a new unique cache key is created to avoid past `GetCustomerInfoOperation` to share outdated data. If we simply added a random number to the `GetCustomerInfoOperation` cache key, the new test would have also passed. No other test verified the caching behavior, which is what the new `testGetSubscriberInfoDoesNotMakeTwoRequests` checks.
NachoSoto
added a commit
to RevenueCat/purchases-android
that referenced
this pull request
Feb 22, 2022
Android equivalent to RevenueCat/purchases-ios#1249 and RevenueCat/purchases-ios#1292. Finishes [sc-12802]. ## Background Before this change, the sequence illustrated by the new test `"gets updated customer after posting receipt data"` would fail: - GET /subscribers/ - POST /receipts - GET /subscribers/ When the first GET request finishes, the second one shares the cache key, so it receives the (soon to be) outdated `CustomerInfo`. ## The fix Unfortunately this fix is isolated for this specific issue, and not a generalized one. I came up with several other alternatives, but what I ended up going with here involves the least amount of moving pieces. If a `getCustomerInfo` request is enqueued with `postReceiptData` in the queue, then a new unique cache key is created to avoid past `getCustomerInfo` to share outdated data. If we simply added a random number to the `getCustomerInfo` cache key, the test `"given multiple get calls for same subscriber, only one is triggered"` fails, so that's still verifying the previous behavior works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example for
https://app.shortcut.com/revenuecat/story/12802/api-cache-too-aggressive
https://app.shortcut.com/revenuecat/story/12888/api-calls-are-not-always-executed-in-order
https://app.shortcut.com/revenuecat/story/9521/rewrite-httpclient-for-purchases-ios