diff --git a/Mac/AccountStats/AccountStatsViewModel.swift b/Mac/AccountStats/AccountStatsViewModel.swift index 772decfd7..644575b5a 100644 --- a/Mac/AccountStats/AccountStatsViewModel.swift +++ b/Mac/AccountStats/AccountStatsViewModel.swift @@ -60,7 +60,7 @@ struct AccountStatsData { NotificationCenter.default.post(name: .AccountStatsDidChange, object: self) Task { - await AccountManager.shared.vacuumAllDatabases() + await appDelegate.vacuumAllDatabases() isVacuuming = false refresh() } @@ -118,17 +118,13 @@ private extension AccountStatsViewModel { func databaseSize(for account: Account) -> Int { let dataFolder = account.dataFolder as NSString let baseNames = ["DB.sqlite3", "FeedSettings.db", "Sync.sqlite3"] - // WAL databases create multiple files. - let suffixes = ["", "-wal", "-shm", "-journal"] var totalSize = 0 for baseName in baseNames { - for suffix in suffixes { - let path = dataFolder.appendingPathComponent(baseName + suffix) - if let attributes = try? FileManager.default.attributesOfItem(atPath: path), - let size = attributes[FileAttributeKey.size] as? Int { - totalSize += size - } + let path = dataFolder.appendingPathComponent(baseName) + if let attributes = try? FileManager.default.attributesOfItem(atPath: path), + let size = attributes[FileAttributeKey.size] as? Int { + totalSize += size } } diff --git a/Mac/Activity/ActivityLogWindowController.swift b/Mac/Activity/ActivityLogWindowController.swift index cfb23f6af..ca0709989 100644 --- a/Mac/Activity/ActivityLogWindowController.swift +++ b/Mac/Activity/ActivityLogWindowController.swift @@ -27,13 +27,11 @@ import ActivityLog private var copyButton: NSButton? private var hasBeenShown = false - /// Activity IDs for which we've logged the start entry. - private var loggedStartIDs = Set() /// Activity IDs for which we've logged the completion entry. private var loggedCompletionIDs = Set() /// Number of text entries appended to the text view. private var textEntryCount = 0 - /// Maximum text entries before rebuilding (2 per activity: start + completion). + /// Maximum text entries before rebuilding. private static let maxTextEntries = 1000 private var needsRebuild = false @@ -221,7 +219,6 @@ private extension ActivityLogWindowController { } func reloadEntries() { - loggedStartIDs.removeAll() loggedCompletionIDs.removeAll() textEntryCount = 0 @@ -230,11 +227,6 @@ private extension ActivityLogWindowController { let combined = NSMutableAttributedString() for activity in allActivities { - if activity.state == .running || activity.state == .completed || activity.state == .failed { - combined.append(startAttributedString(for: activity)) - loggedStartIDs.insert(activity.id) - textEntryCount += 1 - } if activity.state == .completed || activity.state == .failed { combined.append(completionAttributedString(for: activity)) loggedCompletionIDs.insert(activity.id) @@ -259,14 +251,6 @@ private extension ActivityLogWindowController { var didAppend = false for activity in allActivities { - let isStarted = activity.state == .running || activity.state == .completed || activity.state == .failed - if isStarted && !loggedStartIDs.contains(activity.id) { - textView.textStorage?.append(startAttributedString(for: activity)) - loggedStartIDs.insert(activity.id) - textEntryCount += 1 - didAppend = true - } - let isFinished = activity.state == .completed || activity.state == .failed if isFinished && !loggedCompletionIDs.contains(activity.id) { textView.textStorage?.append(completionAttributedString(for: activity)) @@ -300,26 +284,6 @@ private extension ActivityLogWindowController { // MARK: - Attributed Strings - func startAttributedString(for activity: Activity) -> NSAttributedString { - let result = NSMutableAttributedString() - - let date = activity.startDate ?? Date() - appendTimestamp(date, to: result) - - let startAttributes: [NSAttributedString.Key: Any] = [ - .foregroundColor: NSColor.systemBlue, - .font: NSFont.monospacedSystemFont(ofSize: Self.fontSize, weight: .medium), - .paragraphStyle: Self.entryParagraphStyle - ] - result.append(NSAttributedString(string: "▶ ", attributes: startAttributes)) - - appendSource(for: activity, to: result) - appendKindAndDetail(for: activity, to: result) - appendNewline(to: result) - - return result - } - func completionAttributedString(for activity: Activity) -> NSAttributedString { let result = NSMutableAttributedString() diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 31dc784ff..778f86095 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -827,13 +827,19 @@ extension AppDelegate { @IBAction func vacuumDatabases(_ sender: Any?) { Task { - await AccountManager.shared.vacuumAllDatabases() - await vacuumAndLog(databasePath: HTMLMetadataDatabase.shared.databasePath) { - await HTMLMetadataDatabase.shared.vacuum() - } - await vacuumAndLog(databasePath: ImageMetadataDatabase.shared.databasePath) { - await ImageMetadataDatabase.shared.vacuum() - } + await vacuumAllDatabases() + } + } + + /// Vacuum every database the app owns — per-account databases plus the + /// app-level HTMLMetadata and ImageMetadata databases. + func vacuumAllDatabases() async { + await AccountManager.shared.vacuumAllDatabases() + await vacuumAndLog(databasePath: HTMLMetadataDatabase.shared.databasePath) { + await HTMLMetadataDatabase.shared.vacuum() + } + await vacuumAndLog(databasePath: ImageMetadataDatabase.shared.databasePath) { + await ImageMetadataDatabase.shared.vacuum() } } diff --git a/Modules/Account/Sources/Account/FeedSettingsDatabase.swift b/Modules/Account/Sources/Account/FeedSettingsDatabase.swift index 2da950d4e..539e4fe3d 100644 --- a/Modules/Account/Sources/Account/FeedSettingsDatabase.swift +++ b/Modules/Account/Sources/Account/FeedSettingsDatabase.swift @@ -62,7 +62,6 @@ final class FeedSettingsDatabase: Sendable { self.serialDispatchQueue = DispatchQueue(label: "FeedSettingsDatabase") self.database = FMDatabase.openAndSetUpDatabase(path: databasePath) serialDispatchQueue.sync { [database] in - database.executeStatements("PRAGMA journal_mode = WAL;") database.runCreateStatements(Self.tableCreationStatements) } vacuumIfNeeded() diff --git a/Modules/ErrorLog/Sources/ErrorLog/ErrorLogDatabase.swift b/Modules/ErrorLog/Sources/ErrorLog/ErrorLogDatabase.swift index 6f733a6ee..9e1e4816b 100644 --- a/Modules/ErrorLog/Sources/ErrorLog/ErrorLogDatabase.swift +++ b/Modules/ErrorLog/Sources/ErrorLog/ErrorLogDatabase.swift @@ -23,7 +23,6 @@ public actor ErrorLogDatabase { public init(databasePath: String) { self.databasePath = databasePath let database = FMDatabase.openAndSetUpDatabase(path: databasePath) - database.executeStatements("PRAGMA journal_mode = WAL;") database.runCreateStatements(Self.tableCreationStatements) ErrorLogTable.pruneEntries(limit: Self.pruneLimit, database: database) database.vacuumIfNeeded() diff --git a/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDatabase.swift b/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDatabase.swift index 2c5c9abb9..fcd18285d 100644 --- a/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDatabase.swift +++ b/Modules/HTMLMetadata/Sources/HTMLMetadata/HTMLMetadataDatabase.swift @@ -55,7 +55,6 @@ public final actor HTMLMetadataDatabase { private init(databasePath: String) { self.databasePath = databasePath let database = FMDatabase.openAndSetUpDatabase(path: databasePath) - database.executeStatements("PRAGMA journal_mode = WAL;") database.runCreateStatements(Self.tableCreationStatements) self.database = database diff --git a/Modules/Images/Sources/Images/ImageMetadataDatabase.swift b/Modules/Images/Sources/Images/ImageMetadataDatabase.swift index d29177b27..bfcba88de 100644 --- a/Modules/Images/Sources/Images/ImageMetadataDatabase.swift +++ b/Modules/Images/Sources/Images/ImageMetadataDatabase.swift @@ -41,12 +41,6 @@ import RSDatabaseObjC .appendingPathComponent("ImageMetadata.db").path self.databasePath = databasePath let queue = DatabaseQueue(databasePath: databasePath) - queue.runInDatabaseSync { result in - guard let database = try? result.get() else { - return - } - database.executeStatements("PRAGMA journal_mode = WAL;") - } try? queue.runCreateStatements(Self.tableCreationStatements) self.queue = queue diff --git a/Modules/RSDatabase/Sources/RSDatabase/DatabaseQueue.swift b/Modules/RSDatabase/Sources/RSDatabase/DatabaseQueue.swift index 9b416be68..18b000e68 100644 --- a/Modules/RSDatabase/Sources/RSDatabase/DatabaseQueue.swift +++ b/Modules/RSDatabase/Sources/RSDatabase/DatabaseQueue.swift @@ -202,6 +202,9 @@ private extension DatabaseQueue { func openDatabase(_ database: FMDatabase) { database.open() + // All databases are single-connection and serialized — WAL gains us nothing + // and produces extra -wal/-shm files that bloat on disk. + database.executeStatements("PRAGMA journal_mode = DELETE;") database.executeStatements("PRAGMA synchronous = 1;") database.setShouldCacheStatements(true) } diff --git a/Modules/RSDatabase/Sources/RSDatabase/FMDatabase+Extras.swift b/Modules/RSDatabase/Sources/RSDatabase/FMDatabase+Extras.swift index 80890e196..bb2d4ef10 100644 --- a/Modules/RSDatabase/Sources/RSDatabase/FMDatabase+Extras.swift +++ b/Modules/RSDatabase/Sources/RSDatabase/FMDatabase+Extras.swift @@ -15,6 +15,9 @@ public extension FMDatabase { let database = FMDatabase(path: path)! database.open() + // All databases are single-connection and serialized — WAL gains us nothing + // and produces extra -wal/-shm files that bloat on disk. + database.executeStatements("PRAGMA journal_mode = DELETE;") database.executeStatements("PRAGMA synchronous = 1;") database.setShouldCacheStatements(true) diff --git a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift index a8a3181fa..46fb543de 100644 --- a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift +++ b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift @@ -25,10 +25,11 @@ nonisolated public struct SpecialCase { return false } - /// Returns true if the URL’s host matches one of the supplied domain names. + /// Returns true if the URL’s host belongs to one of the supplied domains. /// /// Unlike `urlStringContainSpecialCase`, this checks only the host component — not the path or query. /// A leading `www.` on the URL’s host is treated as optional, so `example.com` in `domains` matches a host of either `example.com` or `www.example.com`. + /// Subdomains also match: `micro.blog` in `domains` matches a host of `gruber.micro.blog`. /// The supplied `domains` are assumed to already be lowercased and to have any leading `www.` stripped. public static func urlStringMatchesDomain(_ urlString: String, _ domains: [String]) -> Bool { guard let url = URL(string: urlString), let host = url.host()?.lowercased(with: localeForLowercasing) else { @@ -36,7 +37,10 @@ nonisolated public struct SpecialCase { } let normalizedHost = stringByStrippingWWWPrefix(host) for domain in domains { - if normalizedHost == domain { + if domain.isEmpty { + continue + } + if normalizedHost == domain || normalizedHost.hasSuffix("." + domain) { return true } } diff --git a/Shared/AccountType+Helpers.swift b/Shared/AccountType+Helpers.swift index b333eb958..3fd1b2daf 100644 --- a/Shared/AccountType+Helpers.swift +++ b/Shared/AccountType+Helpers.swift @@ -49,7 +49,7 @@ extension AccountType { var logColor: NSColor { switch self { case .onMyMac: - return .labelColor + return .onMyMacLogColor case .cloudKit: return .systemPurple case .feedly: @@ -104,3 +104,17 @@ extension AccountType { } } + +#if os(macOS) +extension NSColor { + + private static let onMyMacLogLightColor = NSColor(red: 0x4A / 255.0, green: 0x55 / 255.0, blue: 0x60 / 255.0, alpha: 1.0) + private static let onMyMacLogDarkColor = NSColor(red: 0xB0 / 255.0, green: 0xBA / 255.0, blue: 0xC4 / 255.0, alpha: 1.0) + + /// Activity Log color for the On My Mac account. Slate gray — darker on light backgrounds, lighter on dark. + static let onMyMacLogColor = NSColor(name: "onMyMacLogColor") { appearance in + let isDark = appearance.bestMatch(from: [.darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark]) != nil + return isDark ? onMyMacLogDarkColor : onMyMacLogLightColor + } +} +#endif