-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactors #2860 extracting it to a separate type so we can easily extend it to pre-warm the image cache as well (PWL-10).
- Loading branch information
Showing
9 changed files
with
293 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// PaywallCacheWarming.swift | ||
// | ||
// Created by Nacho Soto on 8/7/23. | ||
|
||
import Foundation | ||
|
||
protocol PaywallCacheWarmingType: Sendable { | ||
|
||
func warmUpEligibilityCache(offerings: Offerings) | ||
|
||
} | ||
|
||
final class PaywallCacheWarming: PaywallCacheWarmingType { | ||
|
||
private let introEligibiltyChecker: TrialOrIntroPriceEligibilityCheckerType | ||
|
||
init(introEligibiltyChecker: TrialOrIntroPriceEligibilityCheckerType) { | ||
self.introEligibiltyChecker = introEligibiltyChecker | ||
} | ||
|
||
func warmUpEligibilityCache(offerings: Offerings) { | ||
let productIdentifiers = Set<String>( | ||
offerings | ||
.all | ||
.values | ||
.lazy | ||
.flatMap(\.productIdentifiersInPaywall) | ||
) | ||
|
||
guard !productIdentifiers.isEmpty else { return } | ||
|
||
Logger.debug(Strings.eligibility.warming_up_eligibility_cache(products: productIdentifiers)) | ||
self.introEligibiltyChecker.checkEligibility(productIdentifiers: productIdentifiers) { _ in } | ||
} | ||
|
||
} | ||
|
||
private extension Offering { | ||
|
||
var productIdentifiersInPaywall: Set<String> { | ||
guard let paywall = self.paywall else { return [] } | ||
|
||
let packageTypes = Set(paywall.config.packages) | ||
return Set( | ||
self.availablePackages | ||
.lazy | ||
.filter { packageTypes.contains($0.identifier) } | ||
.map(\.storeProduct.productIdentifier) | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// MockPaywallCacheWarming.swift | ||
// | ||
// Created by Nacho Soto on 8/7/23. | ||
|
||
import Foundation | ||
@testable import RevenueCat | ||
|
||
final class MockPaywallCacheWarming: PaywallCacheWarmingType { | ||
|
||
private let _invokedWarmUpEligibilityCache: Atomic<Bool> = false | ||
private let _invokedWarmUpEligibilityCacheOfferings: Atomic<Offerings?> = nil | ||
|
||
var invokedWarmUpEligibilityCache: Bool { | ||
get { return self._invokedWarmUpEligibilityCache.value } | ||
set { self._invokedWarmUpEligibilityCache.value = newValue } | ||
} | ||
|
||
var invokedWarmUpEligibilityCacheOfferings: Offerings? { | ||
get { return self._invokedWarmUpEligibilityCacheOfferings.value } | ||
set { self._invokedWarmUpEligibilityCacheOfferings.value = newValue } | ||
} | ||
|
||
func warmUpEligibilityCache(offerings: Offerings) { | ||
self.invokedWarmUpEligibilityCache = true | ||
self.invokedWarmUpEligibilityCacheOfferings = offerings | ||
} | ||
|
||
} |
Oops, something went wrong.