Perf: update CustomerInfo cache before anything else#2865
Conversation
There was a problem hiding this comment.
I also extracted this into a method because it's going to grow more in #2860.
There was a problem hiding this comment.
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
tonidero
left a comment
There was a problem hiding this comment.
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 <ignaciosoto90@gmail.com>
I noticed the order of cache updates on SDK initialization was:
OfferingsProductEntitlementMappingCustomerInfoThis is inefficient because fetching
CustomerInfofirst 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 aCustomerInfoupdate.Example log from before:
The new order is:
CustomerInfoProductEntitlementMappingOfferingsNote: I recommend reviewing the diff ignoring whitespace.