From 6b5bb4f178d3e22590fee1a12457db9d8d97f391 Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 11 Mar 2021 14:08:00 +0800 Subject: [PATCH] chore: make the database request Fail-Fast --- .../Service/APIService/APIService+Reblog.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Mastodon/Service/APIService/APIService+Reblog.swift b/Mastodon/Service/APIService/APIService+Reblog.swift index 5525fe5bf..a0268b345 100644 --- a/Mastodon/Service/APIService/APIService+Reblog.swift +++ b/Mastodon/Service/APIService/APIService+Reblog.swift @@ -70,7 +70,7 @@ extension APIService { let managedObjectContext = self.backgroundManagedObjectContext return managedObjectContext.performChanges { - let _requestMastodonUser: MastodonUser? = { + guard let requestMastodonUser: MastodonUser = { let request = MastodonUser.sortedFetchRequest request.predicate = MastodonUser.predicate(domain: mastodonAuthenticationBox.domain, id: requestMastodonUserID) request.fetchLimit = 1 @@ -81,8 +81,11 @@ extension APIService { assertionFailure(error.localizedDescription) return nil } - }() - let _oldToot: Toot? = { + }() else { + return + } + + guard let oldToot: Toot = { let request = Toot.sortedFetchRequest request.predicate = Toot.predicate(domain: domain, id: statusID) request.fetchLimit = 1 @@ -94,13 +97,10 @@ extension APIService { assertionFailure(error.localizedDescription) return nil } - }() - - guard let requestMastodonUser = _requestMastodonUser, - let oldToot = _oldToot else { - assertionFailure() + }() else { return } + APIService.CoreData.merge(toot: oldToot, entity: entity.reblog ?? entity, requestMastodonUser: requestMastodonUser, domain: mastodonAuthenticationBox.domain, networkDate: response.networkDate) if boostKind == .undoBoost { oldToot.update(reblogsCount: NSNumber(value: max(0, oldToot.reblogsCount.intValue - 1)))