diff --git a/Loop/Managers/Alerts/AlertManager.swift b/Loop/Managers/Alerts/AlertManager.swift index ca0142193d..e30acf9d69 100644 --- a/Loop/Managers/Alerts/AlertManager.swift +++ b/Loop/Managers/Alerts/AlertManager.swift @@ -507,7 +507,7 @@ extension AlertManager { await withCheckedContinuation { continuation in let startDate = Date() - .days(3.5) // Report the last 3 and half days of alerts let header = "## Alerts\n" - alertStore.executeQuery(since: startDate, limit: 100) { result in + alertStore.executeQuery(since: startDate, limit: 100, ascending: false) { result in switch result { case .failure: continuation.resume(returning: header) diff --git a/Loop/Managers/Alerts/AlertStore.swift b/Loop/Managers/Alerts/AlertStore.swift index d8d6db7e5c..cc2e7837eb 100644 --- a/Loop/Managers/Alerts/AlertStore.swift +++ b/Loop/Managers/Alerts/AlertStore.swift @@ -422,15 +422,15 @@ extension AlertStore { case failure(Error) } - func executeQuery(fromQueryAnchor queryAnchor: QueryAnchor? = nil, since date: Date, excludingFutureAlerts: Bool = true, now: Date = Date(), limit: Int, completion: @escaping (AlertQueryResult) -> Void) { + func executeQuery(fromQueryAnchor queryAnchor: QueryAnchor? = nil, since date: Date, excludingFutureAlerts: Bool = true, now: Date = Date(), limit: Int, ascending: Bool = true, completion: @escaping (AlertQueryResult) -> Void) { let sinceDateFilter = SinceDateFilter(predicateExpressionNotYetExpired: predicateExpressionNotYetExpired, date: date, excludingFutureAlerts: excludingFutureAlerts, now: now) - executeAlertQuery(fromQueryAnchor: queryAnchor, queryFilter: sinceDateFilter, limit: limit, completion: completion) + executeAlertQuery(fromQueryAnchor: queryAnchor, queryFilter: sinceDateFilter, limit: limit, ascending: ascending, completion: completion) } - func executeAlertQuery(fromQueryAnchor queryAnchor: QueryAnchor?, queryFilter: QueryFilter? = nil, limit: Int, completion: @escaping (AlertQueryResult) -> Void) { + func executeAlertQuery(fromQueryAnchor queryAnchor: QueryAnchor?, queryFilter: QueryFilter? = nil, limit: Int, ascending: Bool = true, completion: @escaping (AlertQueryResult) -> Void) { var queryAnchor = queryAnchor ?? QueryAnchor() var queryResult = [SyncAlertObject]() var queryError: Error? @@ -449,7 +449,7 @@ extension AlertStore { } else { storedRequest.predicate = queryAnchorPredicate } - storedRequest.sortDescriptors = [NSSortDescriptor(key: "modificationCounter", ascending: true)] + storedRequest.sortDescriptors = [NSSortDescriptor(key: "modificationCounter", ascending: ascending)] storedRequest.fetchLimit = limit do {