GetCustomerInfoOperation: improve logic for caching responses#1292
Merged
Conversation
|
This pull request has been linked to: |
joshdholtz
requested changes
Feb 14, 2022
joshdholtz
left a comment
Member
There was a problem hiding this comment.
Fix looks good! Kind of wish it was a generalized solution but 🤷♂️ Just one small suggestion on tests.
aboedo
reviewed
Feb 14, 2022
Contributor
Author
Me too trust me 😕 this fix isn't very satisfying. But understanding the whole issue now (that's why I documented here why it happens), I couldn't come up with something general that still avoids duplicated requests most of the time. |
daef173 to
bb29082
Compare
This was referenced Feb 14, 2022
aboedo
approved these changes
Feb 15, 2022
Contributor
Author
|
I'll wait for @taquitos to give this the thumbs up. |
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.
1ef3def to
98213d8
Compare
Contributor
Author
|
I implemented this on Android too: RevenueCat/purchases-android#486 |
Contributor
Author
|
@joshdholtz the changes look good to you? |
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.
NachoSoto
added a commit
that referenced
this pull request
Sep 19, 2022
…iptDataOperation` in progress Fixes [CSDK-419]. This is an improvement over the fix in #1292. In there, we avoided appending on an existing `CustomerInfoOperation` if there were any `PostReceiptDataOperation`s in progress, because those might come back with outdated entitlements. This fix removes that cache key hack, and instead *reuses* the entire response to that `PostReceiptDataOperation` by "stealing" that request's cache key. This is perfectly captured by the existing test `BackendPostReceiptDataTests.testGetsUpdatedSubscriberInfoAfterPost`, added in #1292. Amazingly enough, that test still passes with one minor (:panda:) change: the entire process requires one fewer API call :tada:
NachoSoto
added a commit
that referenced
this pull request
Sep 21, 2022
…iptDataOperation` in progress (#1911) Fixes [CSDK-419]. This is an improvement over the fix in #1292. In there, we avoided appending on an existing `CustomerInfoOperation` if there were any `PostReceiptDataOperation`s in progress, because those might come back with outdated entitlements. This fix removes that cache key hack, and instead *reuses* the entire response to that `PostReceiptDataOperation` by "stealing" that request's cache key. This is perfectly captured by the existing test `BackendPostReceiptDataTests.testGetsUpdatedSubscriberInfoAfterPost`, added in #1292. Amazingly enough, that test still passes with one minor change: the entire process requires one fewer API call 🎉 🐼 [CSDK-419]: https://revenuecats.atlassian.net/browse/CSDK-419?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
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.
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:#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
HTTPClientis 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
GetCustomerInfoOperationrequest is enqueued withPostReceiptDataOperationin the queue, then a new unique cache key is created to avoid pastGetCustomerInfoOperationto share outdated data.If we simply added a random number to the
GetCustomerInfoOperationcache key, the new test would have also passed. No other test verified the caching behavior, which is what the newtestGetSubscriberInfoDoesNotMakeTwoRequestschecks.