Improve search

This commit is contained in:
Justin Mazzocchi 2021-02-06 17:20:15 -08:00
parent 45820517e9
commit c0ca3f3ad3
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 4 additions and 10 deletions

View file

@ -35,8 +35,9 @@ extension SearchService: CollectionService {
guard let search = search else { return Empty().eraseToAnyPublisher() }
return mastodonAPIClient.request(ResultsEndpoint.search(search))
.flatMap { results in contentDatabase.insert(results: results).collect().map { _ in results } }
.handleEvents(receiveOutput: { resultsSubject.send(($0, search)) })
.flatMap(contentDatabase.insert(results:))
.ignoreOutput()
.eraseToAnyPublisher()
}
}

View file

@ -17,7 +17,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
super.init(collectionService: searchService, identityContext: identityContext)
$query.removeDuplicates()
.throttle(for: .seconds(Self.throttleInterval), scheduler: DispatchQueue.global(), latest: true)
.debounce(for: .seconds(Self.debounceInterval), scheduler: DispatchQueue.global())
.combineLatest($scope.removeDuplicates())
.sink { [weak self] in
self?.request(
@ -28,13 +28,6 @@ public final class SearchViewModel: CollectionItemsViewModel {
.store(in: &cancellables)
}
public override var updates: AnyPublisher<CollectionUpdate, Never> {
// Since results are processed through the DB to determine CW expansion state etc they can arrive erratically
super.updates
.throttle(for: .seconds(Self.throttleInterval), scheduler: DispatchQueue.global(), latest: true)
.eraseToAnyPublisher()
}
public override func requestNextPage(fromIndexPath indexPath: IndexPath) {
guard scope != .all else { return }
@ -46,7 +39,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
}
private extension SearchViewModel {
static let throttleInterval: TimeInterval = 0.5
static let debounceInterval: TimeInterval = 0.25
}
private extension SearchScope {