Fix: Auto-delete logs did not clear heap
This commit is contained in:
@@ -48,11 +48,16 @@ extension SQLiteDatabase {
|
|||||||
/// - Returns: `true` if at least one row was deleted.
|
/// - Returns: `true` if at least one row was deleted.
|
||||||
@discardableResult func dnsLogsDeleteOlderThan(days: Int) throws -> Bool {
|
@discardableResult func dnsLogsDeleteOlderThan(days: Int) throws -> Bool {
|
||||||
guard days > 0 else { return false }
|
guard days > 0 else { return false }
|
||||||
return try self.run(sql: "DELETE FROM cache WHERE ts < strftime('%s', 'now', ?);",
|
func delFrom(_ table: String) throws -> Bool {
|
||||||
bind: [BindText("-\(days) days")]) {
|
return try self.run(sql: "DELETE FROM \(table) WHERE ts < strftime('%s', 'now', ?);",
|
||||||
try ifStep($0, SQLITE_DONE)
|
bind: [BindText("-\(days) days")]) {
|
||||||
return numberOfChanges > 0
|
try ifStep($0, SQLITE_DONE)
|
||||||
|
return numberOfChanges > 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let didDelHeap = try delFrom("heap")
|
||||||
|
let didDelCache = try delFrom("cache")
|
||||||
|
return didDelHeap || didDelCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,13 @@ struct TheGreatDestroyer {
|
|||||||
DispatchQueue.global().async {
|
DispatchQueue.global().async {
|
||||||
defer { sync.continue() }
|
defer { sync.continue() }
|
||||||
QLog.Info("Auto-delete logs")
|
QLog.Info("Auto-delete logs")
|
||||||
guard let success = try? AppDB?.dnsLogsDeleteOlderThan(days: days), success else {
|
do {
|
||||||
return // nothing changed
|
if try AppDB!.dnsLogsDeleteOlderThan(days: days) {
|
||||||
|
sync.needsReloadDB()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
QLog.Warning("Couldn't auto-delete logs, \(error)")
|
||||||
}
|
}
|
||||||
sync.needsReloadDB()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user