Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions superwall/src/main/java/com/superwall/sdk/config/PaywallPreload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay

class PaywallPreload(
val factory: Factory,
Expand Down Expand Up @@ -52,6 +53,30 @@ class PaywallPreload(
preloadingDisabled = config.preloadingDisabled,
)
val confirmedAssignments = storage.getConfirmedAssignments()

// If there's a prioritized campaign, preload its paywalls first.
val prioritizedCampaignId = config.prioritizedCampaignId
if (prioritizedCampaignId != null) {
val prioritizedTriggers =
triggers.filter { trigger ->
trigger.rules.any { it.experimentGroupId == prioritizedCampaignId }
}.toSet()
if (prioritizedTriggers.isNotEmpty()) {
val prioritizedIds =
ConfigLogic.getAllActiveTreatmentPaywallIds(
triggers = prioritizedTriggers,
confirmedAssignments = confirmedAssignments,
unconfirmedAssignments = assignments.unconfirmedAssignments,
expressionEvaluator = expressionEvaluator,
)
preloadPaywalls(paywallIdentifiers = prioritizedIds)

// Delay before preloading the rest to avoid resource contention.
delay(5000)
Comment thread
ianrumac marked this conversation as resolved.
Comment thread
ianrumac marked this conversation as resolved.
}
}

// Then preload all remaining paywalls.
val paywallIds =
ConfigLogic.getAllActiveTreatmentPaywallIds(
triggers = triggers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data class Config(
@SerialName("build_id") val buildId: String,
@SerialName("bundle_id_config") val bundleIdConfig: String? = null,
@SerialName("test_mode_user_ids") val testModeUserIds: List<TestStoreUser>? = null,
@SerialName("prioritized_campaign_id") val prioritizedCampaignId: String? = null,
) : SerializableEntity {
init {
locales = localizationConfig.locales.map { it.locale }.toSet()
Expand Down
Loading