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

GetCustomerInfoAPI: avoid making a request if there's any PostReceiptDataOperation in progress #1911

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

NachoSoto
Copy link
Contributor

@NachoSoto NachoSoto commented Sep 16, 2022

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 PostReceiptDataOperations 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 🎉 🐼

@NachoSoto NachoSoto added the perf label Sep 16, 2022
@NachoSoto NachoSoto requested review from aboedo and a team September 16, 2022 20:22
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

A couple of things but looking good!

Sources/Networking/Caching/CustomerInfoCallback.swift Outdated Show resolved Hide resolved
let completion: Completion
var cacheKey: String
var source: NetworkOperation.Type
var completion: Completion
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add another init instead of making this mutable? Seems safer to me but lmk if you think there are problems with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd recommend reading on Swift's value types. This isn't like having mutable data in other languages, it's only mutable for mutables copies, and even then, because it doesn't have reference semantics, you can't have spooky action at a distance by changing one "instance" and mutating something else. So it's perfectly safe.

Sources/Networking/Caching/CustomerInfoCallback.swift Outdated Show resolved Hide resolved
@NachoSoto
Copy link
Contributor Author

@aboedo I'll wait for you since this is a pretty critical change and I want to make sure you're ok with it too.

…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:
@@ -432,8 +432,7 @@ class BackendPostReceiptDataTests: BaseBackendTests {

expect(self.httpClient.calls.map { $0.request.path }) == [
getCustomerInfoPath,
.postReceiptData,
getCustomerInfoPath
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🐼

@NachoSoto NachoSoto merged commit 43d474d into main Sep 21, 2022
@NachoSoto NachoSoto deleted the get-customer-append-to-push branch September 21, 2022 20:34
NachoSoto added a commit that referenced this pull request Sep 27, 2022
**This is an automatic release.**

### New Features
* 🚨 `StoreKit 2` is now enabled by default 🚨 (#1922) via NachoSoto
(@NachoSoto)
* Extracted `PurchasesType` and `PurchasesSwiftType` (#1912) via
NachoSoto (@NachoSoto)
### Bugfixes
* `StoreKit 1`: changed result of cancelled purchases to be consistent
with `StoreKit 2` (#1910) via NachoSoto (@NachoSoto)
* `PaymentQueueWrapper`: handle promotional purchase requests from App
Store when SK1 is disabled (#1901) via NachoSoto (@NachoSoto)
### Other Changes
* Fixed iOS 12 tests (#1936) via NachoSoto (@NachoSoto)
* `CacheableNetworkOperation`: fixed race condition in new test (#1932)
via NachoSoto (@NachoSoto)
* `BasePurchasesTests`: changed default back to SK1 (#1935) via
NachoSoto (@NachoSoto)
* `Logger`: refactored default `LogLevel` definition (#1934) via
NachoSoto (@NachoSoto)
* `AppleReceipt`: refactored declarations into nested types (#1933) via
NachoSoto (@NachoSoto)
* `Integration Tests`: relaunch tests when retrying failures (#1925) via
NachoSoto (@NachoSoto)
* `CircleCI`: downgraded release jobs to Xcode 13.x (#1927) via
NachoSoto (@NachoSoto)
* `ErrorUtils`: added test to verify that `PublicError`s can be
`catch`'d as `ErrorCode` (#1924) via NachoSoto (@NachoSoto)
* `StoreKitIntegrationTests`: print `AppleReceipt` data whenever
`verifyEntitlementWentThrough` fails (#1929) via NachoSoto (@NachoSoto)
* `OperationQueue`: log debug message when requests are found in cache
and skipped (#1926) via NachoSoto (@NachoSoto)
* `GetCustomerInfoAPI`: avoid making a request if there's any
`PostReceiptDataOperation` in progress (#1911) via NachoSoto
(@NachoSoto)
* `PurchaseTester`: allow HTTP requests and enable setting `ProxyURL`
(#1917) via NachoSoto (@NachoSoto)
@vegaro vegaro added pr:other and removed pr:perf labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants