Skip to content

Commit be515de

Browse files
committed
Improving the internalSave(_:) function
1 parent b01374f commit be515de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

WordPress/Classes/Utility/ContextManager+ErrorHandling.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,21 @@ extension LegacyContextFactory {
6767
extension ManagedObjectContextFactory {
6868

6969
func internalSave(_ context: NSManagedObjectContext) {
70+
guard context.hasChanges else {
71+
return
72+
}
73+
7074
let inserted = Array(context.insertedObjects)
7175
do {
7276
try context.obtainPermanentIDs(for: inserted)
7377
} catch {
7478
DDLogError("Error obtaining permanent object IDs for \(inserted), \(error)")
7579
}
7680

77-
if context.hasChanges {
78-
do {
79-
try context.save()
80-
} catch {
81-
handleSaveError(error as NSError, in: context)
82-
}
81+
do {
82+
try context.save()
83+
} catch {
84+
handleSaveError(error as NSError, in: context)
8385
}
8486
}
8587

0 commit comments

Comments
 (0)