From feedf2913dc0b3bb172b7f048fbd19b14e16a315 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 2 Nov 2026 10:21:38 -0800 Subject: [PATCH] Remove some unused code and database columns. --- .../Sources/Images/DownloadFailureTable.swift | 6 ++---- .../Sources/Images/DownloadedImageCache.swift | 2 +- .../Sources/Images/FeedIconURLTable.swift | 4 +--- .../Sources/Images/HomePageFaviconTable.swift | 8 ++++---- .../Images/Sources/Images/ImageDatabase.swift | 17 ++++++++--------- .../Images/SingleFaviconDownloader.swift | 2 +- .../ArticleThumbnailFinderTests.swift | 8 ++++---- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Modules/Images/Sources/Images/DownloadFailureTable.swift b/Modules/Images/Sources/Images/DownloadFailureTable.swift index a3c168e43..857996c33 100644 --- a/Modules/Images/Sources/Images/DownloadFailureTable.swift +++ b/Modules/Images/Sources/Images/DownloadFailureTable.swift @@ -17,7 +17,6 @@ struct DownloadFailureTable { private struct Column { static let url = "url" static let lastChecked = "lastChecked" - static let statusCode = "statusCode" } /// Returns all failures as `url : lastFailureDate`. @@ -39,11 +38,10 @@ struct DownloadFailureTable { return results } - static func save(url: String, statusCode: Int?, database: FMDatabase) { + static func save(url: String, database: FMDatabase) { let dictionary: DatabaseDictionary = [ Column.url: url, - Column.lastChecked: Date().timeIntervalSince1970, - Column.statusCode: statusCode as Any + Column.lastChecked: Date().timeIntervalSince1970 ] database.insertRow(dictionary, insertType: .orReplace, tableName: name) } diff --git a/Modules/Images/Sources/Images/DownloadedImageCache.swift b/Modules/Images/Sources/Images/DownloadedImageCache.swift index 84fd9fa61..4722e1a7a 100644 --- a/Modules/Images/Sources/Images/DownloadedImageCache.swift +++ b/Modules/Images/Sources/Images/DownloadedImageCache.swift @@ -273,7 +273,7 @@ private extension DownloadedImageCache { activityLog.didFail(activityOwner, kind: activityKind, error: error) } if !error.isTransient { - ImageDatabase.shared.recordFailure(url: url, statusCode: error.statusCode) + ImageDatabase.shared.recordFailure(url: url) } return .failure(error) } diff --git a/Modules/Images/Sources/Images/FeedIconURLTable.swift b/Modules/Images/Sources/Images/FeedIconURLTable.swift index 2980ebcbc..200ece492 100644 --- a/Modules/Images/Sources/Images/FeedIconURLTable.swift +++ b/Modules/Images/Sources/Images/FeedIconURLTable.swift @@ -16,7 +16,6 @@ struct FeedIconURLTable { private struct Column { static let feedURL = "feedURL" static let iconURL = "iconURL" - static let lastChecked = "lastChecked" } static func fetchAll(database: FMDatabase) -> [String: String] { @@ -40,8 +39,7 @@ struct FeedIconURLTable { static func save(feedURL: String, iconURL: String, database: FMDatabase) { let dictionary: DatabaseDictionary = [ Column.feedURL: feedURL, - Column.iconURL: iconURL, - Column.lastChecked: Date().timeIntervalSince1970 + Column.iconURL: iconURL ] database.insertRow(dictionary, insertType: .orReplace, tableName: name) } diff --git a/Modules/Images/Sources/Images/HomePageFaviconTable.swift b/Modules/Images/Sources/Images/HomePageFaviconTable.swift index f69980905..3f88ca5f7 100644 --- a/Modules/Images/Sources/Images/HomePageFaviconTable.swift +++ b/Modules/Images/Sources/Images/HomePageFaviconTable.swift @@ -10,10 +10,10 @@ import RSDatabase import RSDatabaseObjC /// `faviconURL` is `nil` when the homepage has no usable favicon. -public struct HomePageFaviconRecord: Sendable { - public let homePageURL: String - public let faviconURL: String? - public let lastChecked: Date +struct HomePageFaviconRecord: Sendable { + let homePageURL: String + let faviconURL: String? + let lastChecked: Date } struct HomePageFaviconTable { diff --git a/Modules/Images/Sources/Images/ImageDatabase.swift b/Modules/Images/Sources/Images/ImageDatabase.swift index a6792b22b..88a6ff4a6 100644 --- a/Modules/Images/Sources/Images/ImageDatabase.swift +++ b/Modules/Images/Sources/Images/ImageDatabase.swift @@ -17,8 +17,7 @@ import RSParser public static let shared = ImageDatabase() - public static let failureRetryDays = 5 - private static let failureRetentionDays = 33 + private static let failureRetryDays = 5 public let databasePath: String @@ -33,9 +32,9 @@ import RSParser private var urlsUnsuitableForThumbnails = Set() private static let tableCreationStatements = """ - CREATE TABLE IF NOT EXISTS downloadFailure (url TEXT PRIMARY KEY NOT NULL, statusCode INTEGER, lastChecked REAL NOT NULL); + 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, 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, byteCount INTEGER NOT NULL, pixelWidth INTEGER, pixelHeight INTEGER, lastAccessed REAL NOT NULL, etag TEXT, lastModified TEXT, nextCheck REAL NOT NULL); """ @@ -47,9 +46,9 @@ import RSParser /// Tables and columns imported from ImageMetadata.db, which shipped before Images.db replaced it. nonisolated private static let legacyTableColumns = [ - (table: "downloadFailure", columns: "url, statusCode, lastChecked"), + (table: "downloadFailure", columns: "url, lastChecked"), (table: "homePageFavicon", columns: "homePageURL, faviconURL, lastChecked"), - (table: "feedIconURL", columns: "feedURL, iconURL, lastChecked") + (table: "feedIconURL", columns: "feedURL, iconURL") ] private convenience init() { @@ -72,7 +71,7 @@ import RSParser loadCachesFromDatabase() - let failureCutoff = Date().timeIntervalSince1970 - TimeInterval(days: Self.failureRetentionDays) + let failureCutoff = Date().timeIntervalSince1970 - TimeInterval(days: Self.failureRetryDays) queue.runInDatabase { database in DownloadFailureTable.removeExpired(olderThan: failureCutoff, database: database) database.executeStatements(Self.dropArticleThumbnailTableStatement) @@ -132,10 +131,10 @@ import RSParser return Date().timeIntervalSince(lastFailure) < TimeInterval(days: Self.failureRetryDays) } - public func recordFailure(url: String, statusCode: Int?) { + public func recordFailure(url: String) { failureDates[url] = Date() queue.runInDatabase { database in - DownloadFailureTable.save(url: url, statusCode: statusCode, database: database) + DownloadFailureTable.save(url: url, database: database) } } diff --git a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift index 56ff5a6bb..250e48206 100644 --- a/Modules/Images/Sources/Images/SingleFaviconDownloader.swift +++ b/Modules/Images/Sources/Images/SingleFaviconDownloader.swift @@ -81,7 +81,7 @@ private extension SingleFaviconDownloader { iconImage = IconImage(image) ImageDatabase.shared.clearFailure(url: faviconURL) } else { - ImageDatabase.shared.recordFailure(url: faviconURL, statusCode: nil) + ImageDatabase.shared.recordFailure(url: faviconURL) } } catch { // A non-image response usually means the site has no favicon at this URL. diff --git a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift index 71f0d1d77..13dbffc9c 100644 --- a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift +++ b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift @@ -45,7 +45,7 @@ private typealias ArticleAttachment = Articles.Attachment let finder = ArticleThumbnailFinder(imageDatabase: imageDatabase) let article = makeArticle(imageURL: "https://example.com/image.jpg", thumbnailURL: "https://example.com/thumbnail.jpg") - imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg", statusCode: 404) + imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg") #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/image.jpg") } @@ -76,7 +76,7 @@ private typealias ArticleAttachment = Articles.Attachment #expect(finder.thumbnailURL(for: articleWithImage, mode: .small) == "https://example.com/uploads/photo.jpg") #expect(finder.thumbnailURL(for: articleWithoutImage, mode: .small) == nil) - imageDatabase.recordFailure(url: "https://example.com/uploads/photo.jpg", statusCode: 404) + imageDatabase.recordFailure(url: "https://example.com/uploads/photo.jpg") finder.thumbnailURLDidFail("https://example.com/uploads/photo.jpg") #expect(finder.thumbnailURL(for: articleWithImage, mode: .small) == "https://example.com/uploads/second-photo.jpg") } @@ -89,7 +89,7 @@ private typealias ArticleAttachment = Articles.Attachment await finder.findThumbnailURLs(for: [article]) #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/thumbnail.jpg") - imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg", statusCode: 404) + imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg") finder.thumbnailURLDidFail("https://example.com/thumbnail.jpg") #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/uploads/photo.jpg") } @@ -122,7 +122,7 @@ private typealias ArticleAttachment = Articles.Attachment #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/thumbnail.jpg") // A failure with no notification shows whether the choice was made again. - imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg", statusCode: 404) + imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg") let sameImages = makeArticle(contentHTML: "

Edited.

", imageURL: "https://example.com/image.jpg", thumbnailURL: "https://example.com/thumbnail.jpg") #expect(finder.thumbnailURL(for: sameImages, mode: .small) == "https://example.com/thumbnail.jpg")