From 5f64e5e08353bd4d34024fc1f39eb10c1a1e84eb Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 16 Jul 2021 11:22:34 +0800 Subject: [PATCH] fix: app may crash due to old version insert duplicate entities issue --- .../SearchHistory/SearchHistoryViewModel.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift index 19bb875c9..acfd995ff 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift @@ -38,9 +38,13 @@ final class SearchHistoryViewModel { for objectID in objectIDs { guard let searchHistory = try? managedObjectContext.existingObject(with: objectID) as? SearchHistory else { continue } 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 { - items.append(.hashtag(objectID: hashtag.objectID)) + let item: SearchHistoryItem = .hashtag(objectID: hashtag.objectID) + guard !items.contains(item) else { continue } + items.append(item) } else { // TODO: status }