Skip to content

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

Merged
NachoSoto merged 2 commits into
mainfrom
get-customer-append-to-push
Sep 21, 2022
Merged

GetCustomerInfoAPI: avoid making a request if there's any PostReceiptDataOperation in progress#1911
NachoSoto merged 2 commits into
mainfrom
get-customer-append-to-push

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Sep 16, 2022

Copy link
Copy Markdown
Contributor

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 a team and aboedo September 16, 2022 20:22

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread Sources/Networking/Caching/CustomerInfoCallback.swift Outdated

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Sources/Networking/Caching/CustomerInfoCallback.swift Outdated
@NachoSoto

Copy link
Copy Markdown
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:
@NachoSoto NachoSoto force-pushed the get-customer-append-to-push branch from 2611441 to f6d9502 Compare September 19, 2022 18:02
expect(self.httpClient.calls.map { $0.request.path }) == [
getCustomerInfoPath,
.postReceiptData,
getCustomerInfoPath

Copy link
Copy Markdown
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