From fc7dc03cee03754d4e4b083be9c9dfef4823f7b9 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 18 Aug 2018 23:54:13 +0200 Subject: [PATCH] don't block main thread during search // FREEBIE --- .../ConversationSearchViewController.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift index 2f7b16119..5628548cb 100644 --- a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift +++ b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift @@ -376,12 +376,19 @@ class ConversationSearchViewController: UITableViewController { return } - self.uiDatabaseConnection.read { transaction in - self.searchResultSet = self.searcher.results(searchText: searchText, transaction: transaction, contactsManager: self.contactsManager) - } - - // TODO: more performant way to do this? - self.tableView.reloadData() + var searchResults: SearchResultSet? + self.uiDatabaseConnection.asyncRead({ transaction in + searchResults = self.searcher.results(searchText: searchText, transaction: transaction, contactsManager: self.contactsManager) + }, + completionBlock: { + guard let results = searchResults else { + owsFail("\(self.logTag) in \(#function) searchResults was unexpectedly nil") + return + } + + self.searchResultSet = results + self.tableView.reloadData() + }) } // MARK: - UIScrollViewDelegate