mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 10:47:21 +00:00
Report per-database duration when vacuuming.
This commit is contained in:
1 parent
1a6ed87632
commit
6fdda05ec3
20 files changed
+120
-61
No files matched your search
@@ -500,47 +500,40 @@ private extension ActivityLogWindowController {
|
||||
case .downloadHTMLMetadata(let urlString):
|
||||
return "Downloading metadata \(urlString)"
|
||||
case .subscribeFeed:
|
||||
return descriptionWithDetail("Subscribing to feed", activity: activity)
|
||||
return "Subscribing to feed"
|
||||
case .renameFeed:
|
||||
return descriptionWithDetail("Renaming feed", activity: activity)
|
||||
return "Renaming feed"
|
||||
case .removeFeed:
|
||||
return descriptionWithDetail("Removing feed", activity: activity)
|
||||
return "Removing feed"
|
||||
case .moveFeed:
|
||||
return descriptionWithDetail("Moving feed", activity: activity)
|
||||
return "Moving feed"
|
||||
case .addFeed:
|
||||
return descriptionWithDetail("Adding feed", activity: activity)
|
||||
return "Adding feed"
|
||||
case .createFolder:
|
||||
return descriptionWithDetail("Creating folder", activity: activity)
|
||||
return "Creating folder"
|
||||
case .renameFolder:
|
||||
return descriptionWithDetail("Renaming folder", activity: activity)
|
||||
return "Renaming folder"
|
||||
case .removeFolder:
|
||||
return descriptionWithDetail("Removing folder", activity: activity)
|
||||
return "Removing folder"
|
||||
case .restoreFolder:
|
||||
return descriptionWithDetail("Restoring folder", activity: activity)
|
||||
return "Restoring folder"
|
||||
case .markArticles:
|
||||
return descriptionWithDetail("Marking articles", activity: activity)
|
||||
return "Marking articles"
|
||||
case .cleanUpCloudKitRecords:
|
||||
return "Weekly record cleanup"
|
||||
case .uploadNewArticles:
|
||||
return descriptionWithDetail("Uploading new articles", activity: activity)
|
||||
return "Uploading new articles"
|
||||
case .subscribeToCloudKitZone:
|
||||
return descriptionWithDetail("Subscribing to zone changes", activity: activity)
|
||||
return "Subscribing to zone changes"
|
||||
case .vacuumDatabase:
|
||||
return descriptionWithDetail("Vacuuming databases", activity: activity)
|
||||
return "Vacuuming database"
|
||||
case .validateCredentials:
|
||||
return descriptionWithDetail("Validating credentials", activity: activity)
|
||||
return "Validating credentials"
|
||||
case .exportOPML:
|
||||
return descriptionWithDetail("Exporting OPML", activity: activity)
|
||||
return "Exporting OPML"
|
||||
}
|
||||
}
|
||||
|
||||
private func descriptionWithDetail(_ prefix: String, activity: Activity) -> String {
|
||||
if let detail = activity.detail {
|
||||
return "\(prefix): \(detail)"
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
func color(for owner: ActivityOwner) -> NSColor {
|
||||
switch owner {
|
||||
case .account(let accountID):
|
||||
|
||||
@@ -395,11 +395,18 @@ private extension ActivityWindowController {
|
||||
}
|
||||
|
||||
func attributedDisplayName(for activity: Activity) -> NSAttributedString {
|
||||
// AppKit ignores NSTextField.lineBreakMode for attributedStringValue,
|
||||
// so the paragraph style has to ride along on the attributed string.
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.lineBreakMode = .byTruncatingTail
|
||||
|
||||
let primaryAttributes: [NSAttributedString.Key: Any] = [
|
||||
.foregroundColor: NSColor.labelColor
|
||||
.foregroundColor: NSColor.labelColor,
|
||||
.paragraphStyle: paragraphStyle
|
||||
]
|
||||
let secondaryAttributes: [NSAttributedString.Key: Any] = [
|
||||
.foregroundColor: NSColor.secondaryLabelColor
|
||||
.foregroundColor: NSColor.secondaryLabelColor,
|
||||
.paragraphStyle: paragraphStyle
|
||||
]
|
||||
|
||||
switch activity.kind {
|
||||
@@ -487,7 +494,7 @@ private extension ActivityWindowController {
|
||||
case .subscribeToCloudKitZone:
|
||||
return NSLocalizedString("Subscribing to zone changes", comment: "Activity kind")
|
||||
case .vacuumDatabase:
|
||||
return NSLocalizedString("Vacuuming databases", comment: "Activity kind")
|
||||
return NSLocalizedString("Vacuuming database", comment: "Activity kind")
|
||||
case .validateCredentials:
|
||||
return NSLocalizedString("Validating credentials", comment: "Activity kind")
|
||||
case .exportOPML:
|
||||
|
||||
@@ -21,6 +21,7 @@ import Secrets
|
||||
import CrashReporter
|
||||
import Sparkle
|
||||
import Images
|
||||
import HTMLMetadata
|
||||
|
||||
let appName = "NetNewsWire"
|
||||
|
||||
@@ -822,9 +823,23 @@ 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func vacuumAndLog(databasePath: String, _ work: () async -> Void) async {
|
||||
let activityLog = ActivityLog.shared
|
||||
let id = activityLog.createActivity(owner: .app, kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(databasePath))
|
||||
activityLog.didStart(id: id)
|
||||
await work()
|
||||
activityLog.didComplete(id: id)
|
||||
}
|
||||
|
||||
@IBAction func openImageCacheFolder(_ sender: Any?) {
|
||||
NSWorkspace.shared.open(AppConfig.cacheFolder)
|
||||
}
|
||||
|
||||
@@ -1092,16 +1092,14 @@ public enum FetchType {
|
||||
|
||||
// MARK: - Vacuum
|
||||
|
||||
public func vacuumDatabases() {
|
||||
// Underlying vacuum work is dispatched async behind each `vacuum()` call,
|
||||
// so we can't await actual completion here — report initiation only.
|
||||
let activityLog = ActivityLog.shared
|
||||
let id = activityLog.createActivity(owner: .account(accountID), kind: .vacuumDatabase, detail: nameForDisplay)
|
||||
activityLog.didStart(id: id)
|
||||
database.vacuum()
|
||||
feedSettingsDatabase.vacuum()
|
||||
delegate.vacuumDatabases()
|
||||
activityLog.didComplete(id: id, durationIsSignificant: false)
|
||||
public func vacuumDatabases() async {
|
||||
try? await logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(database.databasePath)) {
|
||||
await database.vacuum()
|
||||
}
|
||||
try? await logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(feedSettingsDatabase.databasePath)) {
|
||||
await feedSettingsDatabase.vacuum()
|
||||
}
|
||||
await delegate.vacuumDatabases(for: self)
|
||||
}
|
||||
|
||||
public func fetchCloudKitStats(progress: @escaping CloudKitStatsProgressHandler) async throws -> CloudKitStats {
|
||||
|
||||
@@ -53,7 +53,7 @@ import Secrets
|
||||
|
||||
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?) async throws -> Credentials?
|
||||
|
||||
func vacuumDatabases()
|
||||
func vacuumDatabases(for account: Account) async
|
||||
|
||||
/// Suspend all network activity
|
||||
func suspendNetwork()
|
||||
|
||||
@@ -13,6 +13,7 @@ import RSWeb
|
||||
import Articles
|
||||
import ArticlesDatabase
|
||||
import ErrorLog
|
||||
import ActivityLog
|
||||
|
||||
@MainActor public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
@@ -442,9 +443,14 @@ import ErrorLog
|
||||
// MARK: - Vacuum
|
||||
|
||||
public func vacuumAllDatabases() async {
|
||||
let activityLog = ActivityLog.shared
|
||||
let id = activityLog.createActivity(owner: .app, kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(errorLogDatabase.databasePath))
|
||||
activityLog.didStart(id: id)
|
||||
await errorLogDatabase.vacuum()
|
||||
activityLog.didComplete(id: id)
|
||||
|
||||
for account in accounts {
|
||||
account.vacuumDatabases()
|
||||
await account.vacuumDatabases()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,8 +573,8 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
|
||||
nil
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
Task {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
try? await account.logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(syncDatabase.databasePath)) {
|
||||
await syncDatabase.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,14 @@ final class FeedSettingsDatabase: Sendable {
|
||||
let lastCheckDate: Date?
|
||||
}
|
||||
|
||||
let databasePath: String
|
||||
|
||||
nonisolated(unsafe) private let database: FMDatabase // Used on serial dispatch queue only
|
||||
private let serialDispatchQueue: DispatchQueue
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FeedSettingsDatabase")
|
||||
|
||||
init(databasePath: String) {
|
||||
self.databasePath = databasePath
|
||||
self.serialDispatchQueue = DispatchQueue(label: "FeedSettingsDatabase")
|
||||
self.database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
serialDispatchQueue.sync { [database] in
|
||||
@@ -65,9 +68,12 @@ final class FeedSettingsDatabase: Sendable {
|
||||
vacuumIfNeeded()
|
||||
}
|
||||
|
||||
func vacuum() {
|
||||
serialDispatchQueue.async {
|
||||
self.database.vacuum()
|
||||
func vacuum() async {
|
||||
await withCheckedContinuation { continuation in
|
||||
serialDispatchQueue.async {
|
||||
self.database.vacuum()
|
||||
continuation.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -382,8 +382,8 @@ public enum FeedbinAccountDelegateError: String, Error, Sendable {
|
||||
return try await caller.validateCredentials()
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
Task {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
try? await account.logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(syncDatabase.databasePath)) {
|
||||
await syncDatabase.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,8 +683,8 @@ import Secrets
|
||||
return credentials
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
Task {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
try? await account.logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(syncDatabase.databasePath)) {
|
||||
await syncDatabase.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ import Secrets
|
||||
nil
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
}
|
||||
|
||||
// MARK: Suspend and Resume (for iOS)
|
||||
|
||||
@@ -450,8 +450,8 @@ import Secrets
|
||||
return try await caller.validateCredentials()
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
Task {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
try? await account.logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(syncDatabase.databasePath)) {
|
||||
await syncDatabase.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,8 +505,8 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||
return try await caller.validateCredentials(endpoint: endpoint)
|
||||
}
|
||||
|
||||
func vacuumDatabases() {
|
||||
Task {
|
||||
func vacuumDatabases(for account: Account) async {
|
||||
try? await account.logActivity(kind: .vacuumDatabase, detail: AppConfig.relativeDataPath(syncDatabase.databasePath)) {
|
||||
await syncDatabase.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public struct ArticleChanges: Sendable {
|
||||
case syncSystem // Feedbin, Feedly, etc.: article retention is defined by external system
|
||||
}
|
||||
|
||||
public nonisolated let databasePath: String
|
||||
|
||||
private let articlesTable: ArticlesTable
|
||||
private let queue: DatabaseQueue
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
@@ -53,6 +55,7 @@ public struct ArticleChanges: Sendable {
|
||||
public init(databaseFilePath: String, accountID: String, retentionStyle: RetentionStyle) {
|
||||
Self.logger.debug("Articles Database init \(accountID, privacy: .public)")
|
||||
|
||||
self.databasePath = databaseFilePath
|
||||
let queue = DatabaseQueue(databasePath: databaseFilePath)
|
||||
self.queue = queue
|
||||
self.articlesTable = ArticlesTable(name: DatabaseTableName.articles, accountID: accountID, queue: queue, retentionStyle: retentionStyle)
|
||||
@@ -92,8 +95,8 @@ public struct ArticleChanges: Sendable {
|
||||
|
||||
// MARK: - Vacuum
|
||||
|
||||
public func vacuum() {
|
||||
queue.vacuum()
|
||||
public func vacuum() async {
|
||||
await queue.vacuum()
|
||||
}
|
||||
|
||||
// MARK: - Fetching Articles
|
||||
|
||||
@@ -12,6 +12,8 @@ import RSDatabaseObjC
|
||||
|
||||
public actor ErrorLogDatabase {
|
||||
|
||||
public nonisolated let databasePath: String
|
||||
|
||||
private let database: FMDatabase
|
||||
|
||||
private static let tableCreationStatements = "CREATE TABLE if not EXISTS errors (id INTEGER PRIMARY KEY AUTOINCREMENT, date REAL NOT NULL, sourceName TEXT NOT NULL, sourceID INTEGER NOT NULL, operation TEXT NOT NULL DEFAULT '', fileName TEXT NOT NULL DEFAULT '', functionName TEXT NOT NULL DEFAULT '', lineNumber INTEGER NOT NULL DEFAULT 0, errorMessage TEXT NOT NULL);"
|
||||
@@ -19,6 +21,7 @@ public actor ErrorLogDatabase {
|
||||
private static let pruneLimit = 200
|
||||
|
||||
public init(databasePath: String) {
|
||||
self.databasePath = databasePath
|
||||
let database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
|
||||
@@ -10,14 +10,16 @@ import RSCore
|
||||
import RSDatabase
|
||||
import RSDatabaseObjC
|
||||
|
||||
final actor HTMLMetadataDatabase {
|
||||
public final actor HTMLMetadataDatabase {
|
||||
|
||||
@MainActor static let shared: HTMLMetadataDatabase = {
|
||||
@MainActor public static let shared: HTMLMetadataDatabase = {
|
||||
let databasePath = AppConfig.dataFolder
|
||||
.appendingPathComponent("HTMLMetadata.db").path
|
||||
return HTMLMetadataDatabase(databasePath: databasePath)
|
||||
}()
|
||||
|
||||
public nonisolated let databasePath: String
|
||||
|
||||
private let database: FMDatabase
|
||||
private var cache = [String: CachedRecord]()
|
||||
|
||||
@@ -51,6 +53,7 @@ final actor HTMLMetadataDatabase {
|
||||
private static let transientFailureRetryHours = 5
|
||||
|
||||
private init(databasePath: String) {
|
||||
self.databasePath = databasePath
|
||||
let database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
@@ -71,6 +74,10 @@ final actor HTMLMetadataDatabase {
|
||||
database.vacuumIfNeeded()
|
||||
}
|
||||
|
||||
public func vacuum() {
|
||||
database.vacuum()
|
||||
}
|
||||
|
||||
@objc nonisolated func handleAppDidGoToBackground(_ notification: Notification) {
|
||||
Task {
|
||||
await emptyCache()
|
||||
|
||||
@@ -19,6 +19,8 @@ import RSDatabaseObjC
|
||||
public static let failureRetryDays = 5
|
||||
private static let failureRetentionDays = 33
|
||||
|
||||
public let databasePath: String
|
||||
|
||||
nonisolated static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ImageMetadataDatabase")
|
||||
|
||||
private let queue: DatabaseQueue
|
||||
@@ -37,6 +39,7 @@ import RSDatabaseObjC
|
||||
private init() {
|
||||
let databasePath = AppConfig.dataFolder
|
||||
.appendingPathComponent("ImageMetadata.db").path
|
||||
self.databasePath = databasePath
|
||||
let queue = DatabaseQueue(databasePath: databasePath)
|
||||
queue.runInDatabaseSync { result in
|
||||
guard let database = try? result.get() else {
|
||||
@@ -59,6 +62,12 @@ import RSDatabaseObjC
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Vacuum
|
||||
|
||||
public func vacuum() async {
|
||||
await queue.vacuum()
|
||||
}
|
||||
|
||||
// MARK: - HomePageFavicon
|
||||
|
||||
public func faviconURL(forHomePageURL homePageURL: String) -> String? {
|
||||
|
||||
@@ -57,6 +57,16 @@ import Foundation
|
||||
createFolderIfNecessary(folder)
|
||||
return folder
|
||||
}
|
||||
|
||||
/// Returns the given absolute path relative to `dataFolder`. Used to label
|
||||
/// files in user-visible diagnostics (Activity Log, Error Log).
|
||||
public static func relativeDataPath(_ absolutePath: String) -> String {
|
||||
let prefix = dataFolder.path + "/"
|
||||
if absolutePath.hasPrefix(prefix) {
|
||||
return String(absolutePath.dropFirst(prefix.count))
|
||||
}
|
||||
return absolutePath
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppConfig {
|
||||
|
||||
@@ -163,12 +163,14 @@ public final class DatabaseQueue: Sendable {
|
||||
/// weekly-ish? — to keep up the performance level of a database.
|
||||
/// Generally a thing to do at startup, if it’s been a while
|
||||
/// since the last vacuum() call.
|
||||
public func vacuum() {
|
||||
runInDatabase { result in
|
||||
guard let database = try? result.get() else {
|
||||
return
|
||||
public func vacuum() async {
|
||||
await withCheckedContinuation { continuation in
|
||||
runInDatabase { result in
|
||||
if let database = try? result.get() {
|
||||
database.vacuum()
|
||||
}
|
||||
continuation.resume()
|
||||
}
|
||||
database.vacuum()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import RSDatabaseObjC
|
||||
|
||||
public actor SyncDatabase {
|
||||
private var database: FMDatabase?
|
||||
private let databasePath: String
|
||||
public nonisolated let databasePath: String
|
||||
|
||||
public init(databasePath: String) {
|
||||
let database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
|
||||
Reference in new issue
Block a user