forgot to batch
This commit is contained in:
parent
94512211d8
commit
049f194304
2 changed files with 23 additions and 17 deletions
|
|
@ -115,8 +115,15 @@ class Store: ObservableObject {
|
|||
// MARK: Notifications
|
||||
|
||||
func save(notificationFromMessage message: Message, withSubscription subscription: Subscription) {
|
||||
save(notificationsFromMessages: [message], withSubscription: subscription)
|
||||
}
|
||||
|
||||
func save(notificationsFromMessages messages: [Message], withSubscription subscription: Subscription) {
|
||||
guard !messages.isEmpty else { return }
|
||||
|
||||
context.performAndWait {
|
||||
do {
|
||||
for message in messages {
|
||||
let notification = Notification(context: context)
|
||||
notification.id = message.id
|
||||
notification.time = message.time
|
||||
|
|
@ -130,9 +137,10 @@ class Store: ObservableObject {
|
|||
subscription.addToNotifications(notification)
|
||||
subscription.lastNotificationId = message.id
|
||||
Log.d(Store.tag, "Storing notification with ID \(notification.id ?? "<unknown>")")
|
||||
}
|
||||
try context.save()
|
||||
} catch let error {
|
||||
Log.w(Store.tag, "Cannot store notification (fromMessage)", error)
|
||||
Log.w(Store.tag, "Cannot store notifications (fromMessages)", error)
|
||||
rollbackAndRefresh()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,9 +61,7 @@ struct SubscriptionManager {
|
|||
}
|
||||
Log.d(tag, "Polling success, \(messages.count) new message(s)", messages)
|
||||
if !messages.isEmpty {
|
||||
for message in messages {
|
||||
store.save(notificationFromMessage: message, withSubscription: subscription)
|
||||
}
|
||||
store.save(notificationsFromMessages: messages, withSubscription: subscription)
|
||||
}
|
||||
completionHandler(messages)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue