Skip to content

Commit 4b9e0ba

Browse files
committed
tweak & add comments
1 parent 82a1969 commit 4b9e0ba

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

lib/match-with-schedule-trip.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ SELECT
218218
-- todo: use tz
219219
FROM arrivals_departures ad
220220
WHERE True
221-
-- We can't use a mere \`trip_id = ANY(SELECT trip_id FROM matches)\` because, as of v14, PostgreSQL fails to "push down" the join/filtering [2] into \`arrivals_departures\` even though \`matches\` is materialized and known to be small. By forcing PostgreSQL to "collect" the values from \`matches\` using \`array()\` [0][1], we guide it to todo. (The same applies to \`date\`.)
222-
-- This technique *does not* work (i.e. is slow) when using \`IN\` to filter with (trip_id, date) pairs – using two separate \`= ANY()\` filters is not equivalent, after all! –, so we first filter using \`= ANY()\` on trip_id & date for speed, and then filter on the pairs for correctness.
221+
-- We can't use a mere \`trip_id = ANY(SELECT trip_id FROM matches)\` because, as of v14, PostgreSQL fails to "push down" the join/filtering [2] into \`arrivals_departures\` even though \`matches\` is materialized and known to be small. By forcing PostgreSQL to "collect" the values from \`matches\` using \`array()\` [0][1], we guide it to first collect results and then filter. (The same applies to \`date\`.)
222+
-- This technique *does not* work (i.e. is slow) when using \`IN\` to filter with (trip_id, date) pairs – using two separate \`= ANY()\` filters is not equivalent, after all! –, so we first filter using \`= ANY()\` on trip_id & date for speed, and then additionally filter on the pairs for correctness.
223223
-- [0] https://stackoverflow.com/a/15007154/1072129
224224
-- [1] https://dba.stackexchange.com/a/189255/289704
225225
-- [2] https://stackoverflow.com/a/66626205/1072129
@@ -372,8 +372,8 @@ SELECT
372372
-- todo: use tz
373373
FROM arrivals_departures ad
374374
WHERE True
375-
-- We can't use a mere \`trip_id = ANY(SELECT trip_id FROM matches)\` because, as of v14, PostgreSQL fails to "push down" the join/filtering [2] into \`arrivals_departures\` even though \`matches\` is materialized and known to be small. By forcing PostgreSQL to "collect" the values from \`matches\` using \`array()\` [0][1], we guide it to todo. (The same applies to \`date\`.)
376-
-- This technique *does not* work (i.e. is slow) when using \`IN\` to filter with (trip_id, date) pairs – using two separate \`= ANY()\` filters is not equivalent, after all! –, so we first filter using \`= ANY()\` on trip_id & date for speed, and then filter on the pairs for correctness.
375+
-- We can't use a mere \`trip_id = ANY(SELECT trip_id FROM matches)\` because, as of v14, PostgreSQL fails to "push down" the join/filtering [2] into \`arrivals_departures\` even though \`matches\` is materialized and known to be small. By forcing PostgreSQL to "collect" the values from \`matches\` using \`array()\` [0][1], we guide it to first collect results and then filter. (The same applies to \`date\`.)
376+
-- This technique *does not* work (i.e. is slow) when using \`IN\` to filter with (trip_id, date) pairs – using two separate \`= ANY()\` filters is not equivalent, after all! –, so we first filter using \`= ANY()\` on trip_id & date for speed, and then additionally filter on the pairs for correctness.
377377
-- [0] https://stackoverflow.com/a/15007154/1072129
378378
-- [1] https://dba.stackexchange.com/a/189255/289704
379379
-- [2] https://stackoverflow.com/a/66626205/1072129

lib/match.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ const runGtfsMatching = async (cfg, opt = {}) => {
134134
],
135135
})
136136
// NATS gives separate sequence numbers to both a) messages in a stream and b) messages as (re-)received by a consumer.
137-
// We currently use `msg.seq`. – todo: what is that?
138-
// todo [breaking]: change ot use the stream sequence or remove this metric, as it's misleading!
137+
// We currently use `msg.seq`, which is the stream sequence (not the consumer sequence) of the message.
139138
const natsMsgSeq = new Gauge({
140139
name: 'nats_msg_seq',
141140
help: 'sequence number of the latest NATS message being processed',
@@ -255,7 +254,7 @@ const runGtfsMatching = async (cfg, opt = {}) => {
255254
const tReceived = Date.now()
256255
const {
257256
subject,
258-
seq,
257+
seq, // stream sequence, not consumer sequence
259258
redelivered,
260259
data,
261260
} = msg

lib/soft-exit.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// copied from https://github.com/derhuerst/hafas-gtfs-rt-feed/blob/8.2.6/lib/soft-exit.js
2+
13
const withSoftExit = (softExit) => {
24
let softExiting = false
35
const onExitSignal = () => {

lib/vdv-aus-istfahrt-as-gtfs-rt-tripupdate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const createFormatVdvAusIstFahrtAsGtfsRtTripUpdate = async (cfg) => {
175175
// todo: expose istFahrt.Besetztgrad as VehiclePosition.occupancy_status?
176176
}
177177

178-
// not part of the GTFS Realtime spec, we just use it for matching
178+
// not part of the GTFS Realtime spec, we just use it for matching and/or debug-logging
179179
const route_short_name = istFahrt.LinienText || null
180180
Object.defineProperty(tripUpdate.trip, kRouteShortName, {value: route_short_name})
181181
Object.defineProperty(tripUpdate, kFahrtID, {value: istFahrt.FahrtID ?? null})
@@ -196,4 +196,4 @@ export {
196196
kUmlaufID,
197197
unixTimestampFromIso8601,
198198
createFormatVdvAusIstFahrtAsGtfsRtTripUpdate,
199-
}
199+
}

0 commit comments

Comments
 (0)