From d7171776d387cb55fb31854bd64a2a752769afef Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Tue, 3 Oct 2023 22:50:14 -0400 Subject: [PATCH] optimized search view loading --- Mlem/Models/Trackers/RecentSearchesTracker.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Mlem/Models/Trackers/RecentSearchesTracker.swift b/Mlem/Models/Trackers/RecentSearchesTracker.swift index 07d19f977..fc4214fd0 100644 --- a/Mlem/Models/Trackers/RecentSearchesTracker.swift +++ b/Mlem/Models/Trackers/RecentSearchesTracker.swift @@ -22,23 +22,24 @@ class RecentSearchesTracker: ObservableObject { func reloadRecentSearches(accountId: String?) async throws { defer { hasLoaded = true } - recentSearches = .init() if let accountId { let identifiers = persistenceRepository.loadRecentSearches(for: accountId) + var newSearches: [AnyContentModel] = .init() for id in identifiers { - print(id.contentType, id.contentId) switch id.contentType { case .post: break case .community: let community: CommunityModel = try await communityRepository.loadDetails(for: id.contentId) - recentSearches.append(AnyContentModel(community)) + newSearches.append(AnyContentModel(community)) case .user: let user = try await personRepository.loadDetails(for: id.contentId) - recentSearches.append(AnyContentModel(user)) + newSearches.append(AnyContentModel(user)) } } + + recentSearches = newSearches } }