From ee492f3826205524b185668663a3bb54eaaef667 Mon Sep 17 00:00:00 2001 From: Josh Holtz Date: Tue, 14 Jan 2025 06:15:07 -0600 Subject: [PATCH] Added image caching for icons --- .../Components/PaywallV2CacheWarming.swift | 33 ++++++++++++++++++- Sources/Paywalls/PaywallCacheWarming.swift | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Sources/Paywalls/Components/PaywallV2CacheWarming.swift b/Sources/Paywalls/Components/PaywallV2CacheWarming.swift index ee25132711..cc8a15ce81 100644 --- a/Sources/Paywalls/Components/PaywallV2CacheWarming.swift +++ b/Sources/Paywalls/Components/PaywallV2CacheWarming.swift @@ -53,6 +53,13 @@ extension PaywallComponentsData.PaywallComponentsConfig { switch component { case .text: () + case .icon(let icon): + guard let baseUrl = URL(string: icon.baseUrl) else { + break + } + + urls += icon.formats.imageUrls(base: baseUrl) + urls += icon.overrides?.imageUrls(base: baseUrl) ?? [] case .image(let image): urls += [ image.source.light.heicLowRes, @@ -96,7 +103,31 @@ extension PaywallComponentsData.PaywallComponentsConfig { } -extension PaywallComponent.ThemeImageUrls { +extension PaywallComponent.IconComponent.Formats { + + func imageUrls(base: URL) -> [URL] { + return [ + base.appendingPathComponent(heic) + ] + } + +} + +extension PaywallComponent.ComponentOverrides where T == PaywallComponent.PartialIconComponent { + + func imageUrls(base: URL) -> [URL] { + return [ + self.introOffer?.formats?.imageUrls(base: base) ?? [], + self.states?.selected?.formats?.imageUrls(base: base) ?? [], + self.conditions?.compact?.formats?.imageUrls(base: base) ?? [], + self.conditions?.medium?.formats?.imageUrls(base: base) ?? [], + self.conditions?.expanded?.formats?.imageUrls(base: base) ?? [] + ].flatMap { $0 } + } + +} + +private extension PaywallComponent.ThemeImageUrls { var imageUrls: [URL] { return [ diff --git a/Sources/Paywalls/PaywallCacheWarming.swift b/Sources/Paywalls/PaywallCacheWarming.swift index 5a33ca3054..1a390fbedc 100644 --- a/Sources/Paywalls/PaywallCacheWarming.swift +++ b/Sources/Paywalls/PaywallCacheWarming.swift @@ -178,7 +178,7 @@ private extension Offerings { #if PAYWALL_COMPONENTS private var allImagesInPaywallsV2: Set { - // Attempting to warm up all offerings for Paywalls V2. + // Attempting to warm up all low res images for all offerings for Paywalls V2. // Paywalls V2 paywall are explicitly published so anything that // is here is intended to be displayed. // Also only prewarming low res urls