Skip to content

Commit

Permalink
Timetable bug fixes, ensure search processing is done on a worker thread
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottwilliams committed Oct 2, 2017
1 parent e1ade4c commit ac680c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Proper/Controllers/POIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class POIViewController: UIViewController, ProperViewController, UISearchControl
bar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
}

let searchProducer = point.producer.combineLatest(with: zoom.producer.map({ $0 * 2 })) // widen search radius
let searchProducer = point.producer.combineLatest(with: zoom.producer.map({ $0 * 1.3 })) // widen search radius
.observe(on: searchScheduler)
.throttle(0.5, on: searchScheduler)
.logEvents(identifier: "NearbyStationsViewModel.chain input",
logger: logSignalEvent)
Expand All @@ -139,6 +140,7 @@ class POIViewController: UIViewController, ProperViewController, UISearchControl
disposable += NearbyStationsViewModel.chain(connection: connection, producer: searchProducer)
.observe(on: UIScheduler())
.startWithResult() { result in
assert(Thread.isMainThread)
switch result {
case let .success(stations): self.stations.swap(stations)
case let .failure(error): self.displayError(error)
Expand Down
5 changes: 3 additions & 2 deletions Proper/Services/Timetable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct Timetable {
let args: WampArgs = [route?.identifier, station.identifier].flatMap({ $0 })
+ timestamps(for: timing) as [Any]
+ [count] as [Any]
NSLog("[Timetable] call args: \(args)")
let results = connection.call(proc, with: args)
|> decodeArrivalTimes(connection: connection)
|> { $0.on(value: { advanced = timing.advancedBy(arrivals: $0) }) }
Expand Down Expand Up @@ -238,7 +239,7 @@ extension Timetable {
struct Meta: Argo.Decodable {
let realtime: Bool
static func decode(_ json: JSON) -> Decoded<Timetable.Response.Meta> {
return self.init <^> json <| "realtime"
return self.init <^> (json <| "realtime").or(.success(false))
}
}

Expand All @@ -253,7 +254,7 @@ extension Timetable {
<*> Date.decode(args[1])
<*> Route.decode(args[2])
<*> Optional<String>.decode(args[3])
<*> Meta.decode(args[4])
<*> Meta.decode(args[safe: 4] ?? JSON.null)
})
}
func makeArrival(using connection: ConnectionType) throws -> Arrival {
Expand Down
10 changes: 9 additions & 1 deletion Proper/View Models/NearbyStationsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ struct NearbyStationsViewModel: SignalChain {
})
}

static func limit(producer: SignalProducer<[MutableStation], ProperError>) ->
SignalProducer<[MutableStation], ProperError>
{
return producer.map({ Array($0.prefix(15)) })
}

static func orderedList(producer: SignalProducer<[MutableStation: Distance], ProperError>) ->
SignalProducer<[(MutableStation, Distance)], ProperError>
{
Expand All @@ -98,9 +104,11 @@ struct NearbyStationsViewModel: SignalChain {
static func chain(connection: ConnectionType, producer: SignalProducer<(Point, SearchRadius), ProperError>) ->
SignalProducer<[MutableStation], ProperError>
{
let worker = QueueScheduler(qos: .userInitiated, name: "NearbyStationsViewModel worker")
let producer = SignalProducer.combineLatest(getStations(connection: connection),
producer |> searchArea)
producer |> searchArea).observe(on: worker)
|> curry(filterNearby)(connection)
|> limit
return producer.logEvents(identifier: "NearbyStationsViewModel.chain", logger: logSignalEvent)
}
}
Expand Down

0 comments on commit ac680c0

Please sign in to comment.