fix: app may crash due to old version insert duplicate entities issue

This commit is contained in:
CMK 2021-07-16 11:22:34 +08:00
parent fb6a8a8f93
commit 5f64e5e083
1 changed files with 6 additions and 2 deletions

View File

@ -38,9 +38,13 @@ final class SearchHistoryViewModel {
for objectID in objectIDs { for objectID in objectIDs {
guard let searchHistory = try? managedObjectContext.existingObject(with: objectID) as? SearchHistory else { continue } guard let searchHistory = try? managedObjectContext.existingObject(with: objectID) as? SearchHistory else { continue }
if let account = searchHistory.account { if let account = searchHistory.account {
items.append(.account(objectID: account.objectID)) let item: SearchHistoryItem = .account(objectID: account.objectID)
guard !items.contains(item) else { continue }
items.append(item)
} else if let hashtag = searchHistory.hashtag { } else if let hashtag = searchHistory.hashtag {
items.append(.hashtag(objectID: hashtag.objectID)) let item: SearchHistoryItem = .hashtag(objectID: hashtag.objectID)
guard !items.contains(item) else { continue }
items.append(item)
} else { } else {
// TODO: status // TODO: status
} }