Skip to content

Commit fd6f3ed

Browse files
committed
fix a bug of delete transaction
1 parent 269b2a6 commit fd6f3ed

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Sources/PersistentHistoryTrackingKit/Cleaner.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ struct Cleaner: TransactionCleanerProtocol {
2929
func cleanTransaction(before timestamp: Date?) throws {
3030
guard let timestamp = timestamp else { return }
3131
try backgroundContext.performAndWait {
32-
let request = getPersistentStoreRequest(before: timestamp, for: authors)
33-
try backgroundContext.execute(request)
32+
if let request = getPersistentStoreRequest(before: timestamp, for: authors) {
33+
try backgroundContext.execute(request)
34+
}
3435
}
3536
}
3637

3738
// make a request for delete transactions before timestamp
38-
func getPersistentStoreRequest(before timestamp: Date, for allAuthors: [String]) -> NSPersistentStoreRequest {
39+
func getPersistentStoreRequest(before timestamp: Date, for allAuthors: [String]) -> NSPersistentStoreRequest? {
3940
let historyStoreRequest = NSPersistentHistoryChangeRequest.deleteHistory(before: timestamp)
4041
if let fetchRequest = NSPersistentHistoryTransaction.fetchRequest {
4142
fetchRequest.predicate = createPredicateForAllAuthors(allAuthors: authors)
4243
historyStoreRequest.fetchRequest = fetchRequest
44+
return historyStoreRequest
45+
}
46+
else {
47+
return nil
4348
}
44-
return historyStoreRequest
4549
}
4650

4751
/// create predicate for all authors

0 commit comments

Comments
 (0)