forked from shadowfacts/Tusker
parent
6528070f1c
commit
d8fccc8f1b
|
@ -530,11 +530,34 @@ class MastodonCachePersistentStore: NSPersistentCloudKitContainer {
|
||||||
defer {
|
defer {
|
||||||
PersistentHistoryTokenStore.setToken(token, for: accountInfo)
|
PersistentHistoryTokenStore.setToken(token, for: accountInfo)
|
||||||
}
|
}
|
||||||
let req = NSPersistentHistoryChangeRequest.fetchHistory(after: lastToken)
|
let transactions: [NSPersistentHistoryTransaction]
|
||||||
if let result = try? self.remoteChangesBackgroundContext.execute(req) as? NSPersistentHistoryResult,
|
do {
|
||||||
let transactions = result.result as? [NSPersistentHistoryTransaction],
|
let req = NSPersistentHistoryChangeRequest.fetchHistory(after: lastToken)
|
||||||
!transactions.isEmpty {
|
if let result = try self.remoteChangesBackgroundContext.execute(req) as? NSPersistentHistoryResult {
|
||||||
|
transactions = result.result as? [NSPersistentHistoryTransaction] ?? []
|
||||||
|
} else {
|
||||||
|
logger.error("Unexpectedly non-NSPersistentHistoryResult")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
logger.error("Unable to fetch persistent history results: \(String(describing: error), privacy: .public)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !transactions.isEmpty {
|
||||||
self.processPersistentHistoryTransactions(transactions)
|
self.processPersistentHistoryTransactions(transactions)
|
||||||
|
|
||||||
|
do {
|
||||||
|
// delete history only before the last token, because we don't want to invalidate
|
||||||
|
// the most recent token
|
||||||
|
let deleteReq = NSPersistentHistoryChangeRequest.deleteHistory(before: lastToken)
|
||||||
|
let result = try self.remoteChangesBackgroundContext.execute(deleteReq)
|
||||||
|
if let result = result as? NSPersistentHistoryResult,
|
||||||
|
result.resultType == .statusOnly {
|
||||||
|
logger.info("Delete old persistent history result status: \(result.result as! Int)")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
logger.error("Unable to delete old persistent history: \(String(describing: error), privacy: .public)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue