Use DELETE instead of WAL, since we're not doing concurrent reads on databases.

This commit is contained in:
Brent Simmons committed 2026-05-31 11:58:39 -07:00
1 parent 5a069deae0
commit fea5b057d3
8 files changed
+24 -25

No files matched your search

+5 -9
View File
@@ -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
}
}
+13 -7
View File
@@ -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()
}
}
@@ -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()
@@ -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()
@@ -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
@@ -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
@@ -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)
}
@@ -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)