-
Notifications
You must be signed in to change notification settings - Fork 315
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
Perf
: update CustomerInfo
cache before anything else
#2865
Conversation
@@ -1604,6 +1599,12 @@ private extension Purchases { | |||
self.delegate?.purchases?(self, receivedUpdated: info) | |||
} | |||
|
|||
private func updateOfferingsCache(isAppBackgrounded: Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also extracted this into a method because it's going to grow more in #2860.
@@ -26,6 +26,14 @@ class PurchasesGetOfferingsTests: BasePurchasesTests { | |||
expect(self.mockOfferingsManager.invokedUpdateOfferingsCacheCount).toEventually(equal(1)) | |||
} | |||
|
|||
func testFirstInitializationGetsOfferingsIfAppActiveInCustomEntitlementComputation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateAllCachesIfNeeded
would have meant that this would have now been skipped.
I noticed the order of cache updates on SDK initialization was: - `Offerings` - `ProductEntitlementMapping` - `CustomerInfo` This is inefficient because fetching `CustomerInfo` first is the most important. Also, #2860 will pre-warm intro eligibility, so we want to do that _after_ we might have potentially cleared the intro eligibility cache after a `CustomerInfo` update. _ Note: I recommend reviewing the diff ignoring whitespace._
8e70a22
to
a61f663
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me... With the jittering, I imagine these requests can still happen in different order, but I think that's ok. Leaving others to review first though.
Another question I have. To calculate intro-eligibility, don't we need offerings first? So we can know what products to use to calculate intro eligibility.
We only do jitter if updating caches in the background. This method I'm modifying is called when launching the app and it's in the foreground, so the order will be deterministic.
Yeah that's why pre-warming that is done last, after fetching offerings. Without this change, that might have been done before updating the |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2865 +/- ##
==========================================
+ Coverage 86.48% 86.57% +0.09%
==========================================
Files 217 217
Lines 15513 15511 -2
==========================================
+ Hits 13416 13429 +13
+ Misses 2097 2082 -15 ☔ View full report in Codecov by Sentry. |
Caching
: update CustomerInfo
cache before anything elsePerf
: update CustomerInfo
cache before anything else
**This is an automatic release.** _This release is compatible with Xcode 15 beta 5 and visionOS beta 2_ ### Bugfixes * `xrOS`: fixed `SubscriptionStoreView` for visionOS beta 2 (#2884) via Josh Holtz (@joshdholtz) ### Performance Improvements * `Perf`: update `CustomerInfo` cache before anything else (#2865) via NachoSoto (@NachoSoto) ### Other Changes * `SimpleApp`: added support for localization (#2880) via NachoSoto (@NachoSoto) * `TestStoreProduct`: made available on release builds (#2861) via NachoSoto (@NachoSoto) * `Tests`: increased default logger capacity (#2870) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: removed `invalidateCustomerInfoCache` (#2866) via NachoSoto (@NachoSoto) * `SimpleApp`: updates for TestFlight compatibility (#2862) via NachoSoto (@NachoSoto) * `BasePurchasesTests`: consolidate to only initialize one `DeviceCache` (#2863) via NachoSoto (@NachoSoto) * `Codable`: debug log entire JSON when decoding fails (#2864) via NachoSoto (@NachoSoto) * `IntegrationTests`: replaced `Purchases.shared` with a `throw`ing property (#2867) via NachoSoto (@NachoSoto) * `NetworkError`: 2 new tests to ensure underlying error is included in description (#2843) via NachoSoto (@NachoSoto) * Add SPM `Package.resolved` for Xcode Cloud (#2844) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: added integration test for cancellations (#2849) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: removed `syncPurchases`/`restorePurchases` (#2854) via NachoSoto (@NachoSoto) --------- Co-authored-by: NachoSoto <[email protected]>
I noticed the order of cache updates on SDK initialization was:
Offerings
ProductEntitlementMapping
CustomerInfo
This is inefficient because fetching
CustomerInfo
first is the most important. Also, #2860 will pre-warm intro eligibility, so we want to do that after we might have potentially cleared the intro eligibility cache after aCustomerInfo
update.Example log from before:
The new order is:
CustomerInfo
ProductEntitlementMapping
Offerings
Note: I recommend reviewing the diff ignoring whitespace.