06/23 Fix High-impact issues
This commit is contained in:
@@ -277,13 +277,21 @@ actor APIClient {
|
||||
|
||||
// ── Notification polling (Phase C) ────────────────────────────────────
|
||||
|
||||
// Shared formatter for the ?since= query parameter.
|
||||
// DateFormatter init is expensive — creating one per fetchNotifications()
|
||||
// call (every 60 seconds) adds unnecessary allocations on the sync cycle.
|
||||
private static let notifSinceFmt: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "en_US_POSIX")
|
||||
f.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
||||
return f
|
||||
}()
|
||||
|
||||
/// Fetch notifications, optionally scoped to those created after `since`.
|
||||
func fetchNotifications(since: Date? = nil) async throws -> [APINotification] {
|
||||
var ep = "/api/v1/notifications"
|
||||
if let since {
|
||||
let fmt = DateFormatter()
|
||||
fmt.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
||||
ep += "?since=\(fmt.string(from: since))"
|
||||
ep += "?since=\(Self.notifSinceFmt.string(from: since))"
|
||||
}
|
||||
let result: APINotificationsResponseData = try await request(ep)
|
||||
return result.notifications
|
||||
|
||||
Reference in New Issue
Block a user