diff --git a/main/Base.lproj/Main.storyboard b/main/Base.lproj/Main.storyboard index a86b834..104078e 100644 --- a/main/Base.lproj/Main.storyboard +++ b/main/Base.lproj/Main.storyboard @@ -357,20 +357,27 @@ - + - diff --git a/main/DB/DBWrapper.swift b/main/DB/DBWrapper.swift index 657bc5c..764c6e5 100644 --- a/main/DB/DBWrapper.swift +++ b/main/DB/DBWrapper.swift @@ -40,7 +40,7 @@ class DBWrapper { $0.1 + ($1.1.contains(.ignored) ? 1 : 0)) }} } - func listOfTimes(_ domain: String) -> [(Timestamp, Bool)] { + func listOfTimes(_ domain: String) -> [GroupedTsOccurrence] { return AppDB?.timesForDomain(domain, since: earliestEntry)?.reversed() ?? [] } diff --git a/main/DB/SQDB.swift b/main/DB/SQDB.swift index 8b537f1..14af579 100644 --- a/main/DB/SQDB.swift +++ b/main/DB/SQDB.swift @@ -2,10 +2,6 @@ import Foundation import SQLite3 typealias Timestamp = Int64 -struct GroupedDomain { - let domain: String, total: Int32, blocked: Int32, lastModified: Timestamp - var options: FilterOptions? = nil -} struct FilterOptions: OptionSet { let rawValue: Int32 @@ -196,6 +192,11 @@ private struct DNSQueryT: SQLTable { } } +struct GroupedDomain { + let domain: String, total: Int32, blocked: Int32, lastModified: Timestamp + var options: FilterOptions? = nil +} + extension SQLiteDatabase { // MARK: insert @@ -251,14 +252,18 @@ extension SQLiteDatabase { allDomainsGrouped("WHERE ts >= ? AND ts < ?", bind: [BindInt64(ts1), BindInt64(ts2)]) } - func timesForDomain(_ fullDomain: String, since ts: Timestamp = 0) -> [(Timestamp, Bool)]? { - try? run(sql: "SELECT ts, logOpt FROM req WHERE ts >= ? AND domain = ?;", + func timesForDomain(_ fullDomain: String, since ts: Timestamp = 0) -> [GroupedTsOccurrence]? { + try? run(sql: "SELECT ts, COUNT(ts), SUM(logOpt>0) FROM req WHERE ts >= ? AND domain = ? GROUP BY ts;", bind: [BindInt64(ts), BindText(fullDomain)]) { - allRows($0) { (sqlite3_column_int64($0, 0), sqlite3_column_int($0, 1) > 0) } + allRows($0) { + (sqlite3_column_int64($0, 0), sqlite3_column_int($0, 1), sqlite3_column_int($0, 2)) + } } } } +typealias GroupedTsOccurrence = (ts: Timestamp, total: Int32, blocked: Int32) + // MARK: - DNSFilterT diff --git a/main/Requests/TVCHostDetails.swift b/main/Requests/TVCHostDetails.swift index 3abc58a..89da0a5 100644 --- a/main/Requests/TVCHostDetails.swift +++ b/main/Requests/TVCHostDetails.swift @@ -3,7 +3,7 @@ import UIKit class TVCHostDetails: UITableViewController { public var fullDomain: String! - private var dataSource: [(ts: Timestamp, blocked: Bool)] = [] + private var dataSource: [GroupedTsOccurrence] = [] override func viewDidLoad() { super.viewDidLoad() @@ -26,7 +26,8 @@ class TVCHostDetails: UITableViewController { let cell = tableView.dequeueReusableCell(withIdentifier: "HostDetailCell")! let src = dataSource[indexPath.row] cell.textLabel?.text = src.ts.asDateTime() - cell.imageView?.image = (src.blocked ? UIImage(named: "shield-x") : nil) + cell.detailTextLabel?.text = (src.total > 1) ? "\(src.total)x" : nil + cell.imageView?.image = (src.blocked > 0 ? UIImage(named: "shield-x") : nil) return cell } }