Remove some unused code and database columns.

This commit is contained in:
Brent Simmons committed 2026-11-02 10:21:38 -08:00
1 parent 73f7b374ad
commit feedf2913d
7 files changed
+21 -26

No files matched your search

@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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 {
@@ -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<String>()
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)
}
}
@@ -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.
@@ -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: "<p>Edited.</p>", imageURL: "https://example.com/image.jpg", thumbnailURL: "https://example.com/thumbnail.jpg")
#expect(finder.thumbnailURL(for: sameImages, mode: .small) == "https://example.com/thumbnail.jpg")