- Revamp whole DB to Display flow - Filter Pipeline, arbitrary filtering and sorting - Binary tree arrays for faster lookup & manipulation - DB: introducing custom functions - DB scheme: split req into heap & cache - cache written by GlassVPN only - heap written by Main App only - Introducing DB separation: DBCore, DBCommon, DBAppOnly - Introducing DB data sources: TestDataSource, GroupedDomainDataSource, RecordingsDB, DomainFilter - Background sync: Move entries from cache to heap and notify all observers - GlassVPN: Binary tree filter lookup - GlassVPN: Reusing prepared statement
44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
enum RecordingsDB {
|
|
/// Get last started recording (where `start` is set, but `stop` is not)
|
|
static func getCurrent() -> Recording? { AppDB?.recordingGetOngoing() }
|
|
|
|
/// Create new recording and set `start` timestamp to `now()`
|
|
static func startNew() -> Recording? { try? AppDB?.recordingStartNew() }
|
|
|
|
/// Finalize recording by setting the `stop` timestamp to `now()`
|
|
static func stop(_ r: inout Recording) { AppDB?.recordingStop(&r) }
|
|
|
|
/// Get list of all recordings
|
|
static func list() -> [Recording] { AppDB?.recordingGetAll() ?? [] }
|
|
|
|
/// Copy log entries from generic `heap` table to recording specific `recLog` table
|
|
static func persist(_ r: Recording) { AppDB?.recordingLogsPersist(r) }
|
|
|
|
/// Get list of domains that occured during the recording
|
|
static func details(_ r: Recording) -> [RecordLog] {
|
|
AppDB?.recordingLogsGetGrouped(r) ?? []
|
|
}
|
|
|
|
/// Update `title`, `appid`, and `notes` and post `NotifyRecordingChanged` notification.
|
|
static func update(_ r: Recording) {
|
|
AppDB?.recordingUpdate(r)
|
|
NotifyRecordingChanged.post((r, false))
|
|
}
|
|
|
|
/// Delete whole recording including all entries and post `NotifyRecordingChanged` notification.
|
|
static func delete(_ r: Recording) {
|
|
if (try? AppDB?.recordingDelete(r)) == true {
|
|
NotifyRecordingChanged.post((r, true))
|
|
}
|
|
}
|
|
|
|
/// Delete individual entries from recording while keeping the recording alive.
|
|
/// - Returns: `true` if at least one row is deleted.
|
|
static func deleteDetails(_ r: Recording, domain: String) -> Bool {
|
|
((try? AppDB?.recordingLogsDelete(r.id, matchingDomain: domain)) ?? 0) > 0
|
|
}
|
|
}
|
|
|