From 55f592b7eb3f8fd26a22b4cdd543c449fcb81d36 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 2 Nov 2026 15:23:50 -0800 Subject: [PATCH] Keep icons out of the images folder size limit. Remove icons unused for 180 days. --- .../Sources/Images/DownloadedImageCache.swift | 50 +++++++++++++------ .../Sources/Images/DownloadedImageTable.swift | 15 ++++-- .../Images/Sources/Images/ImageDatabase.swift | 8 ++- .../ArticleThumbnailFinderTests.swift | 2 +- .../DownloadedImageCacheTests.swift | 41 ++++++++++++--- .../ImagesTests/ImageDatabaseTests.swift | 10 ++-- 6 files changed, 95 insertions(+), 31 deletions(-) diff --git a/Modules/Images/Sources/Images/DownloadedImageCache.swift b/Modules/Images/Sources/Images/DownloadedImageCache.swift index f211d6f08..260c344a3 100644 --- a/Modules/Images/Sources/Images/DownloadedImageCache.swift +++ b/Modules/Images/Sources/Images/DownloadedImageCache.swift @@ -28,6 +28,8 @@ extension Notification.Name { /// /// At launch, the least recently used copies are deleted from disk until the rest total no more than /// `maximumStoredByteCount`. The total can go over that until the next launch. +/// Icons don’t count toward the limit and aren’t removed for it, so thumbnails can’t push them out. +/// Instead, icons not used in `unusedIconExpirationInterval` are deleted at launch. /// /// Icons can change at the same URL, so callers that show icons pass `checksForUpdates`. /// An icon used after its `nextCheck` date is still used, and the server is asked in the @@ -71,6 +73,7 @@ extension Notification.Name { nonisolated private static let checkIntervalJitter = 0.2 /// A file and its record are saved moments apart, so anything this recent may be mid-save. nonisolated private static let recentChangeInterval: TimeInterval = 60 + nonisolated private static let unusedIconExpirationInterval = TimeInterval(days: 180) /// Disk keys are hex, so this can’t appear in an image’s own key. nonisolated private static let derivedKeySeparator: Character = "-" nonisolated private static let retryWait: TimeInterval = 37 * 60 @@ -81,6 +84,7 @@ extension Notification.Name { private let downloadQueue = ThumbnailTaskQueue(maximumRunningCount: maximumConcurrentLimitedDownloads, maximumWaitingCount: maximumWaitingLimitedDownloads, maximumRunningCountPerGroup: maximumDownloadsPerHost) private var tasks = [String: Task, Never>]() // url: task private var readDatesNoted = [String: Date]() // url: date + private var iconURLsNoted = Set() private var retryDates = [String: Date]() // url: end of the wait after its last transient failure private var hostRetryDates = [String: Date]() // lowercased host: end of the wait after its last transient failure @@ -152,7 +156,14 @@ extension Notification.Name { /// At most once a day per image: saves the access date, which orders images for removal, /// and, when `checksForUpdates`, checks with the server if the copy is due. /// Callers that keep images in memory call this on memory hits too, so images in use aren’t removed first. + /// + /// `checksForUpdates` means the image is an icon, which is saved once per session, so an image first saved as a thumbnail is kept as an icon. func imageWasUsed(_ url: String, checksForUpdates: Bool) { + if checksForUpdates && !iconURLsNoted.contains(url) { + iconURLsNoted.insert(url) + ImageDatabase.shared.saveDownloadedImageIsIcon(url: url) + } + let now = Date() if let readDate = readDatesNoted[url], now.timeIntervalSince(readDate) < Self.readNoteInterval { return @@ -211,7 +222,7 @@ private extension DownloadedImageCache { } } let maximumByteCount = usesDownloadQueue ? Self.maximumLimitedDownloadByteCount : nil - let result = await downloadImageFromNetwork(url, maximumByteCount: maximumByteCount, activityOwner: activityOwner, activityKind: activityKind, activityDetail: activityDetail) + let result = await downloadImageFromNetwork(url, maximumByteCount: maximumByteCount, isIcon: checksForUpdates, activityOwner: activityOwner, activityKind: activityKind, activityDetail: activityDetail) if usesDownloadQueue { downloadQueue.taskDidFinish(group: host) } @@ -248,7 +259,7 @@ private extension DownloadedImageCache { URL(string: url)?.host()?.lowercased(with: localeForLowercasing) } - func downloadImageFromNetwork(_ url: String, maximumByteCount: Int?, activityOwner: ActivityOwner?, activityKind: ActivityKind?, activityDetail: String?) async -> Result { + func downloadImageFromNetwork(_ url: String, maximumByteCount: Int?, isIcon: Bool, activityOwner: ActivityOwner?, activityKind: ActivityKind?, activityDetail: String?) async -> Result { let activityLog = ActivityLog.shared // Thumbnails log only failures, since a few screens of scrolling would otherwise push out the rest of the log. let logsOnlyFailure = activityOwner == .thumbnailDownloader @@ -258,7 +269,7 @@ private extension DownloadedImageCache { } do { - let (data, downloadResponse) = try await downloadImage(url, maximumByteCount: maximumByteCount) + let (data, downloadResponse) = try await downloadImage(url, maximumByteCount: maximumByteCount, isIcon: isIcon) if !logsOnlyFailure, let activityOwner, let activityKind { let message = downloadResponse.data.map(ActivityLog.dataSizeMessage) activityLog.didComplete(activityOwner, kind: activityKind, message: message, returnedFromCache: downloadResponse.returnedFromCache) @@ -279,7 +290,7 @@ private extension DownloadedImageCache { } } - func downloadImage(_ url: String, maximumByteCount: Int?) async throws(ImageDownloadError) -> (Data, DownloadResponse) { + func downloadImage(_ url: String, maximumByteCount: Int?, isIcon: Bool) async throws(ImageDownloadError) -> (Data, DownloadResponse) { guard let imageURL = URL(string: url) else { throw ImageDownloadError(statusCode: nil, decodingFailed: false, isTransient: false) } @@ -302,7 +313,7 @@ private extension DownloadedImageCache { throw ImageDownloadError(statusCode: statusCode, decodingFailed: false, isTransient: false, rejectedByteCount: data.count) } // Transient, since a captive portal’s login page would otherwise fail every image for days. - guard try await saveImage(data, url: url, httpResponse: httpResponse) else { + guard try await saveImage(data, url: url, httpResponse: httpResponse, isIcon: isIcon) else { throw ImageDownloadError(statusCode: statusCode, decodingFailed: true, isTransient: true) } return (data, downloadResponse) @@ -329,7 +340,7 @@ private extension DownloadedImageCache { /// Returns false, and saves nothing, when the data isn’t an image, such as an HTML error page. /// SVG is saved, though ImageIO can’t read it. /// Throws a transient error, and records nothing, when the file can’t be written. - func saveImage(_ data: Data, url: String, httpResponse: HTTPURLResponse?) async throws(ImageDownloadError) -> Bool { + func saveImage(_ data: Data, url: String, httpResponse: HTTPURLResponse?, isIcon: Bool) async throws(ImageDownloadError) -> Bool { let pixelSize = await Self.pixelSize(data) guard pixelSize != nil || httpResponse?.mimeType == Self.svgMIMEType else { Self.logger.info("Didn’t save unreadable image at \(url)") @@ -346,7 +357,7 @@ private extension DownloadedImageCache { conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse) } let nextCheck = Self.nextCheck(httpResponse, hasValidators: conditionalGetInfo != nil) - ImageDatabase.shared.saveDownloadedImage(DownloadedImageRecord(url: url, pixelSize: pixelSize, conditionalGetInfo: conditionalGetInfo, nextCheck: nextCheck)) + ImageDatabase.shared.saveDownloadedImage(DownloadedImageRecord(url: url, pixelSize: pixelSize, conditionalGetInfo: conditionalGetInfo, nextCheck: nextCheck, isIcon: isIcon)) return true } @@ -375,7 +386,7 @@ private extension DownloadedImageCache { } let httpResponse = downloadResponse.response as? HTTPURLResponse - if let data = downloadResponse.data, !data.isEmpty, let httpResponse, httpResponse.statusIsOK, (try? await saveImage(data, url: url, httpResponse: httpResponse)) == true { + if let data = downloadResponse.data, !data.isEmpty, let httpResponse, httpResponse.statusIsOK, (try? await saveImage(data, url: url, httpResponse: httpResponse, isIcon: true)) == true { Self.logger.info("Replaced changed image at \(url)") await Self.deleteFromDisk(diskCache, keys: [Self.derivedDiskKey(url, suffix: Self.scaledIconSuffix)]) NotificationCenter.default.post(name: .downloadedImageDidChange, object: self, userInfo: [Self.urlKey: url]) @@ -393,7 +404,7 @@ private extension DownloadedImageCache { // MARK: - Removing Images - /// Removes the least recently used images until their files total `maximumStoredByteCount`. + /// Removes the least recently used images, other than icons, until their files total `maximumStoredByteCount`. /// Also removes files with no record and records with no file. func removeImagesOverSizeLimit() async { let startDate = Date() @@ -512,13 +523,15 @@ extension DownloadedImageCache { /// `records` are least recently accessed first. Files with no record and records with no file /// are removed, along with derived copies of removed images. Then, when over `maximumByteCount`, - /// the least recently accessed images are removed. + /// the least recently accessed images are removed. Icons don’t count toward it and aren’t removed for it. + /// Icons not used in `unusedIconExpirationInterval` are removed. /// Nothing changed in the last minute is removed, since it may be in the middle of being saved. /// Images in `urlsInUse` are being read or downloaded, so they’re kept too. @concurrent static func imageRemoval(records: [DownloadedImageUsage], files: [String: StoredFile], urlsInUse: Set, now: Date, maximumByteCount: Int) async -> ImageRemoval { let recentChangeDate = now.addingTimeInterval(-recentChangeInterval) - var recordsToKeep = [(record: DownloadedImageUsage, key: String, byteCount: Int)]() + var recordsCountedTowardLimit = [(record: DownloadedImageUsage, key: String, byteCount: Int)]() + var iconRecords = [(record: DownloadedImageUsage, key: String)]() var recordedKeys = Set() var urls = [String]() for record in records { @@ -526,14 +539,16 @@ extension DownloadedImageCache { recordedKeys.insert(key) if files[key] == nil && record.lastAccessed < recentChangeDate { urls.append(record.url) + } else if record.isIcon { + iconRecords.append((record: record, key: key)) } else { - recordsToKeep.append((record: record, key: key, byteCount: files[key]?.byteCount ?? 0)) + recordsCountedTowardLimit.append((record: record, key: key, byteCount: files[key]?.byteCount ?? 0)) } } var keys = Set(files.filter { !recordedKeys.contains(baseDiskKey($0.key)) && $0.value.modificationDate < recentChangeDate }.keys) - var byteCount = recordsToKeep.reduce(0) { $0 + $1.byteCount } + var byteCount = recordsCountedTowardLimit.reduce(0) { $0 + $1.byteCount } - for (record, key, recordByteCount) in recordsToKeep where !urlsInUse.contains(record.url) { + for (record, key, recordByteCount) in recordsCountedTowardLimit where !urlsInUse.contains(record.url) { if byteCount <= maximumByteCount || record.lastAccessed >= recentChangeDate { break } @@ -542,6 +557,13 @@ extension DownloadedImageCache { byteCount -= recordByteCount } + // Such as icons of deleted feeds. + let unusedIconDate = now.addingTimeInterval(-unusedIconExpirationInterval) + for (record, key) in iconRecords where record.lastAccessed < unusedIconDate && !urlsInUse.contains(record.url) { + urls.append(record.url) + keys.insert(key) + } + // Derived copies go with their images. let removedKeys = keys.union(urls.map(diskKey)) keys.formUnion(files.keys.filter { baseDiskKey($0) != $0 && removedKeys.contains(baseDiskKey($0)) }) diff --git a/Modules/Images/Sources/Images/DownloadedImageTable.swift b/Modules/Images/Sources/Images/DownloadedImageTable.swift index e7907f5af..46a703a44 100644 --- a/Modules/Images/Sources/Images/DownloadedImageTable.swift +++ b/Modules/Images/Sources/Images/DownloadedImageTable.swift @@ -17,6 +17,7 @@ struct DownloadedImageRecord: Sendable { let pixelSize: (width: Int, height: Int)? let conditionalGetInfo: HTTPConditionalGetInfo? let nextCheck: Date + let isIcon: Bool } /// What `DownloadedImageCache` needs to check with the server whether a copy is current. @@ -26,9 +27,11 @@ struct DownloadedImageValidation: Sendable { } /// What `DownloadedImageCache` needs to choose images to remove. +/// Icons don’t count toward the size limit. struct DownloadedImageUsage: Sendable { let url: String let lastAccessed: Date + let isIcon: Bool } /// One row per copy stored by `DownloadedImageCache`. @@ -44,6 +47,7 @@ struct DownloadedImageTable { static let etag = "etag" static let lastModified = "lastModified" static let nextCheck = "nextCheck" + static let isIcon = "isIcon" } /// Keeps each query under the database’s limit on parameters. @@ -74,7 +78,7 @@ struct DownloadedImageTable { /// Least recently accessed first. Nil when the query fails. static func fetchUsageByLeastRecentAccess(database: FMDatabase) -> [DownloadedImageUsage]? { var results = [DownloadedImageUsage]() - guard let resultSet = database.executeQuery("SELECT \(Column.url), \(Column.lastAccessed) FROM \(name) ORDER BY \(Column.lastAccessed);", withArgumentsIn: []) else { + guard let resultSet = database.executeQuery("SELECT \(Column.url), \(Column.lastAccessed), \(Column.isIcon) FROM \(name) ORDER BY \(Column.lastAccessed);", withArgumentsIn: []) else { return nil } defer { @@ -85,7 +89,7 @@ struct DownloadedImageTable { continue } let lastAccessed = Date(timeIntervalSince1970: resultSet.double(forColumn: Column.lastAccessed)) - results.append(DownloadedImageUsage(url: url, lastAccessed: lastAccessed)) + results.append(DownloadedImageUsage(url: url, lastAccessed: lastAccessed, isIcon: resultSet.bool(forColumn: Column.isIcon))) } return results } @@ -113,6 +117,10 @@ struct DownloadedImageTable { database.updateRowsWithValue(Date().timeIntervalSince1970, valueKey: Column.lastAccessed, whereKey: Column.url, equals: url, tableName: name) } + static func saveIsIcon(url: String, database: FMDatabase) { + database.updateRowsWithValue(true, valueKey: Column.isIcon, whereKey: Column.url, equals: url, tableName: name) + } + static func delete(urls: [String], database: FMDatabase) { for urlsChunk in urls.chunked(into: maximumURLsPerQuery) { database.deleteRowsWhere(key: Column.url, equalsAnyValue: urlsChunk, tableName: name) @@ -127,7 +135,8 @@ struct DownloadedImageTable { Column.lastAccessed: Date().timeIntervalSince1970, Column.etag: record.conditionalGetInfo?.etag as Any, Column.lastModified: record.conditionalGetInfo?.lastModified as Any, - Column.nextCheck: record.nextCheck.timeIntervalSince1970 + Column.nextCheck: record.nextCheck.timeIntervalSince1970, + Column.isIcon: record.isIcon ] database.insertRow(dictionary, insertType: .orReplace, tableName: name) } diff --git a/Modules/Images/Sources/Images/ImageDatabase.swift b/Modules/Images/Sources/Images/ImageDatabase.swift index 04ddda056..4f24b0a21 100644 --- a/Modules/Images/Sources/Images/ImageDatabase.swift +++ b/Modules/Images/Sources/Images/ImageDatabase.swift @@ -35,7 +35,7 @@ import RSParser CREATE TABLE IF NOT EXISTS downloadFailure (url TEXT PRIMARY KEY NOT NULL, lastChecked REAL NOT NULL); CREATE TABLE IF NOT EXISTS homePageFavicon (homePageURL TEXT PRIMARY KEY NOT NULL, faviconURL TEXT, lastChecked REAL NOT NULL); CREATE TABLE IF NOT EXISTS feedIconURL (feedURL TEXT PRIMARY KEY NOT NULL, iconURL TEXT NOT NULL); - CREATE TABLE IF NOT EXISTS downloadedImage (url TEXT PRIMARY KEY NOT NULL, pixelWidth INTEGER, pixelHeight INTEGER, lastAccessed REAL NOT NULL, etag TEXT, lastModified TEXT, nextCheck REAL NOT NULL); + CREATE TABLE IF NOT EXISTS downloadedImage (url TEXT PRIMARY KEY NOT NULL, pixelWidth INTEGER, pixelHeight INTEGER, lastAccessed REAL NOT NULL, etag TEXT, lastModified TEXT, nextCheck REAL NOT NULL, isIcon INTEGER NOT NULL DEFAULT 0); """ private static let databaseFileName = "Images.db" @@ -172,6 +172,12 @@ import RSParser } } + func saveDownloadedImageIsIcon(url: String) { + queue.runInDatabase { database in + DownloadedImageTable.saveIsIcon(url: url, database: database) + } + } + func fetchDownloadedImageValidation(url: String) async -> DownloadedImageValidation? { await withCheckedContinuation { continuation in queue.runInDatabase { database in diff --git a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift index b52345e05..c85756089 100644 --- a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift +++ b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift @@ -55,7 +55,7 @@ private typealias ArticleAttachment = Articles.Attachment let finder = ArticleThumbnailFinder(imageDatabase: imageDatabase) let article = makeArticle(imageURL: "https://example.com/image.jpg", thumbnailURL: "https://example.com/logo.png") - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: "https://example.com/logo.png", pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: Date())) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: "https://example.com/logo.png", pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: Date(), isIcon: false)) #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/image.jpg") #expect(!imageDatabase.recentlyFailed(url: "https://example.com/logo.png")) diff --git a/Modules/Images/Tests/ImagesTests/DownloadedImageCacheTests.swift b/Modules/Images/Tests/ImagesTests/DownloadedImageCacheTests.swift index fbf7ec171..e0a9b9683 100644 --- a/Modules/Images/Tests/ImagesTests/DownloadedImageCacheTests.swift +++ b/Modules/Images/Tests/ImagesTests/DownloadedImageCacheTests.swift @@ -17,11 +17,11 @@ import RSCore let longAgo = now.addingTimeInterval(-TimeInterval(days: 10)) let urls = ["https://example.com/a.jpg", "https://example.com/b.jpg", "https://example.com/c.jpg", "https://example.com/just-saved.jpg"] let records = [ - DownloadedImageUsage(url: "https://example.com/no-file.jpg", lastAccessed: longAgo), - DownloadedImageUsage(url: urls[0], lastAccessed: longAgo), - DownloadedImageUsage(url: urls[1], lastAccessed: longAgo), - DownloadedImageUsage(url: urls[2], lastAccessed: longAgo), - DownloadedImageUsage(url: urls[3], lastAccessed: now) + DownloadedImageUsage(url: "https://example.com/no-file.jpg", lastAccessed: longAgo, isIcon: false), + DownloadedImageUsage(url: urls[0], lastAccessed: longAgo, isIcon: false), + DownloadedImageUsage(url: urls[1], lastAccessed: longAgo, isIcon: false), + DownloadedImageUsage(url: urls[2], lastAccessed: longAgo, isIcon: false), + DownloadedImageUsage(url: urls[3], lastAccessed: now, isIcon: false) ] let keys = urls.map { DownloadedImageCache.diskKey($0) } var files = Dictionary(uniqueKeysWithValues: keys.map { ($0, storedFile(longAgo, byteCount: 100)) }) @@ -38,7 +38,7 @@ import RSCore @Test func imagesInUseAreKept() async { let now = Date() let longAgo = now.addingTimeInterval(-TimeInterval(days: 10)) - let records = (0..<3).map { DownloadedImageUsage(url: "https://example.com/\($0).jpg", lastAccessed: longAgo) } + let records = (0..<3).map { DownloadedImageUsage(url: "https://example.com/\($0).jpg", lastAccessed: longAgo, isIcon: false) } let files = Dictionary(uniqueKeysWithValues: records.map { (DownloadedImageCache.diskKey($0.url), storedFile(longAgo, byteCount: 100)) }) let removal = await DownloadedImageCache.imageRemoval(records: records, files: files, urlsInUse: [records[0].url], now: now, maximumByteCount: 200) @@ -50,7 +50,7 @@ import RSCore @Test func derivedCopiesAreKeptAndRemovedWithTheirImages() async { let now = Date() let longAgo = now.addingTimeInterval(-TimeInterval(days: 10)) - let records = (0..<2).map { DownloadedImageUsage(url: "https://example.com/\($0).png", lastAccessed: longAgo.addingTimeInterval(TimeInterval($0))) } + let records = (0..<2).map { DownloadedImageUsage(url: "https://example.com/\($0).png", lastAccessed: longAgo.addingTimeInterval(TimeInterval($0)), isIcon: false) } let removedCopy = DownloadedImageCache.derivedDiskKey(records[0].url, suffix: "144") let keptCopy = DownloadedImageCache.derivedDiskKey(records[1].url, suffix: "144") let orphanedCopy = DownloadedImageCache.derivedDiskKey("https://example.com/gone.png", suffix: "144") @@ -66,6 +66,33 @@ import RSCore #expect(removal.remainingByteCount == 100) } + @Test func iconsDoNotCountTowardLimit() async { + let now = Date() + let longAgo = now.addingTimeInterval(-TimeInterval(days: 10)) + let icon = DownloadedImageUsage(url: "https://example.com/apple-touch-icon.png", lastAccessed: longAgo, isIcon: true) + let thumbnails = (0..<2).map { DownloadedImageUsage(url: "https://example.com/\($0).jpg", lastAccessed: longAgo.addingTimeInterval(TimeInterval($0 + 1)), isIcon: false) } + let records = [icon] + thumbnails + let files = Dictionary(uniqueKeysWithValues: records.map { (DownloadedImageCache.diskKey($0.url), storedFile(longAgo, byteCount: 100)) }) + + let removal = await DownloadedImageCache.imageRemoval(records: records, files: files, urlsInUse: [], now: now, maximumByteCount: 100) + + #expect(removal.urls == [thumbnails[0].url]) + #expect(removal.remainingByteCount == 100) + } + + @Test func iconsNotUsedIn180DaysAreRemoved() async { + let now = Date() + let unusedIcon = DownloadedImageUsage(url: "https://example.com/deleted-feed-icon.png", lastAccessed: now.addingTimeInterval(-TimeInterval(days: 181)), isIcon: true) + let usedIcon = DownloadedImageUsage(url: "https://example.com/feed-icon.png", lastAccessed: now.addingTimeInterval(-TimeInterval(days: 179)), isIcon: true) + let records = [unusedIcon, usedIcon] + let files = Dictionary(uniqueKeysWithValues: records.map { (DownloadedImageCache.diskKey($0.url), storedFile(unusedIcon.lastAccessed, byteCount: 100)) }) + + let removal = await DownloadedImageCache.imageRemoval(records: records, files: files, urlsInUse: [], now: now, maximumByteCount: 1000) + + #expect(removal.urls == [unusedIcon.url]) + #expect(removal.keys == [DownloadedImageCache.diskKey(unusedIcon.url)]) + } + @Test func folderThatCantBeListedHasNoStoredFiles() async { let missingFolder = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString).path let files = await DownloadedImageCache.storedFiles(BinaryDiskCache(folder: missingFolder)) diff --git a/Modules/Images/Tests/ImagesTests/ImageDatabaseTests.swift b/Modules/Images/Tests/ImagesTests/ImageDatabaseTests.swift index 8d917bd44..1ecced3d9 100644 --- a/Modules/Images/Tests/ImagesTests/ImageDatabaseTests.swift +++ b/Modules/Images/Tests/ImagesTests/ImageDatabaseTests.swift @@ -58,11 +58,11 @@ import RSWeb let conditionalGetInfo = try #require(HTTPConditionalGetInfo(lastModified: nil, etag: "\"abc\"")) let imageDatabase = ImageDatabase(databasePath: databasePath) - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: iconURL, pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: nextCheck)) - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: replacedIconURL, pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: nextCheck)) - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: replacedIconURL, pixelSize: (width: 512, height: 512), conditionalGetInfo: nil, nextCheck: nextCheck)) - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: photoURL, pixelSize: (width: 800, height: 600), conditionalGetInfo: conditionalGetInfo, nextCheck: nextCheck)) - imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: unreadableImageURL, pixelSize: nil, conditionalGetInfo: nil, nextCheck: nextCheck)) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: iconURL, pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: nextCheck, isIcon: false)) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: replacedIconURL, pixelSize: (width: 48, height: 48), conditionalGetInfo: nil, nextCheck: nextCheck, isIcon: false)) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: replacedIconURL, pixelSize: (width: 512, height: 512), conditionalGetInfo: nil, nextCheck: nextCheck, isIcon: false)) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: photoURL, pixelSize: (width: 800, height: 600), conditionalGetInfo: conditionalGetInfo, nextCheck: nextCheck, isIcon: false)) + imageDatabase.saveDownloadedImage(DownloadedImageRecord(url: unreadableImageURL, pixelSize: nil, conditionalGetInfo: nil, nextCheck: nextCheck, isIcon: false)) let validation = await imageDatabase.fetchDownloadedImageValidation(url: photoURL) #expect(validation?.conditionalGetInfo == conditionalGetInfo)