From c04d3c26084b895be9f36ee24caa5e8ac76960d6 Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Sat, 7 Oct 2023 08:50:57 +0100 Subject: [PATCH] Avoid search rate limit (#704) --- Mlem/Views/Tabs/Search/SearchResultsView.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Mlem/Views/Tabs/Search/SearchResultsView.swift b/Mlem/Views/Tabs/Search/SearchResultsView.swift index a5a24e989..c9a7b83a4 100644 --- a/Mlem/Views/Tabs/Search/SearchResultsView.swift +++ b/Mlem/Views/Tabs/Search/SearchResultsView.swift @@ -22,7 +22,10 @@ struct SearchResultsView: View { .padding(.top, 8) SearchResultListView(showTypeLabel: searchModel.searchTab == .topResults) } - .onChange(of: searchModel.searchText) { newValue in + .onReceive( + searchModel.$searchText + .debounce(for: .seconds(0.2), scheduler: DispatchQueue.main) + ) { newValue in if searchModel.previousSearchText != newValue { if !newValue.isEmpty { contentTracker.refresh(using: searchModel.performSearch)