mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 17:50:59 +00:00
Improve search
This commit is contained in:
parent
45820517e9
commit
c0ca3f3ad3
2 changed files with 4 additions and 10 deletions
|
@ -35,8 +35,9 @@ extension SearchService: CollectionService {
|
||||||
guard let search = search else { return Empty().eraseToAnyPublisher() }
|
guard let search = search else { return Empty().eraseToAnyPublisher() }
|
||||||
|
|
||||||
return mastodonAPIClient.request(ResultsEndpoint.search(search))
|
return mastodonAPIClient.request(ResultsEndpoint.search(search))
|
||||||
|
.flatMap { results in contentDatabase.insert(results: results).collect().map { _ in results } }
|
||||||
.handleEvents(receiveOutput: { resultsSubject.send(($0, search)) })
|
.handleEvents(receiveOutput: { resultsSubject.send(($0, search)) })
|
||||||
.flatMap(contentDatabase.insert(results:))
|
.ignoreOutput()
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
||||||
super.init(collectionService: searchService, identityContext: identityContext)
|
super.init(collectionService: searchService, identityContext: identityContext)
|
||||||
|
|
||||||
$query.removeDuplicates()
|
$query.removeDuplicates()
|
||||||
.throttle(for: .seconds(Self.throttleInterval), scheduler: DispatchQueue.global(), latest: true)
|
.debounce(for: .seconds(Self.debounceInterval), scheduler: DispatchQueue.global())
|
||||||
.combineLatest($scope.removeDuplicates())
|
.combineLatest($scope.removeDuplicates())
|
||||||
.sink { [weak self] in
|
.sink { [weak self] in
|
||||||
self?.request(
|
self?.request(
|
||||||
|
@ -28,13 +28,6 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
||||||
.store(in: &cancellables)
|
.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) {
|
public override func requestNextPage(fromIndexPath indexPath: IndexPath) {
|
||||||
guard scope != .all else { return }
|
guard scope != .all else { return }
|
||||||
|
|
||||||
|
@ -46,7 +39,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension SearchViewModel {
|
private extension SearchViewModel {
|
||||||
static let throttleInterval: TimeInterval = 0.5
|
static let debounceInterval: TimeInterval = 0.25
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension SearchScope {
|
private extension SearchScope {
|
||||||
|
|
Loading…
Reference in a new issue