Skip to content

Commit

Permalink
Paywalls: pre-warm intro eligibility in background thread (#2925)
Browse files Browse the repository at this point in the history
Follow-up to #2860.
Thanks to integration tests for catching this (#2123).

![image](https://github.com/RevenueCat/purchases-ios/assets/685609/cf1e8e32-5d5e-47ba-b900-394aa780d865)
  • Loading branch information
NachoSoto committed Sep 6, 2023
1 parent 928f121 commit 05388a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1615,21 +1615,26 @@ private extension Purchases {
self.offeringsManager.updateOfferingsCache(appUserID: self.appUserID,
isAppBackgrounded: isAppBackgrounded) { offerings in
if let offering = offerings.value?.current, let paywall = offering.paywall {
let packageTypes = Set(paywall.config.packages)
let products: Set<String> = .init(
offering.availablePackages
.lazy
.filter { packageTypes.contains($0.packageType) }
.map(\.storeProduct.productIdentifier)
)

Logger.debug(Strings.eligibility.warming_up_eligibility_cache(paywall))

self.trialOrIntroPriceEligibilityChecker.checkEligibility(productIdentifiers: products) { _ in }
self.operationDispatcher.dispatchOnWorkerThread {
self.warmUpEligibilityCache(offering: offering, paywall: paywall)
}
}
}
}

private func warmUpEligibilityCache(offering: RCOffering, paywall: PaywallData) {
let packageTypes = Set(paywall.config.packages)
let products: Set<String> = .init(
offering.availablePackages
.lazy
.filter { packageTypes.contains($0.packageType) }
.map(\.storeProduct.productIdentifier)
)

Logger.debug(Strings.eligibility.warming_up_eligibility_cache(paywall))
self.trialOrIntroPriceEligibilityChecker.checkEligibility(productIdentifiers: products) { _ in }
}

}

// MARK: - Deprecations
Expand Down
1 change: 1 addition & 0 deletions Sources/Support/FrameworkDisambiguation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

typealias RCRefundRequestStatus = RefundRequestStatus
typealias RCErrorCode = ErrorCode
typealias RCOffering = Offering
typealias RCStorefront = Storefront

let RCDefaultLogHandler = defaultLogHandler

0 comments on commit 05388a6

Please sign in to comment.