Skip to content

Commit

Permalink
speed up stats_active_trips_by_hour creation ⚡️
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Apr 9, 2024
1 parent 1a488aa commit 6f8c66a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions lib/stats_active_trips_by_hour.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,24 @@ WITH
FROM dates, date_offset
),
min_dep AS (
SELECT t_departure AS t
SELECT min("t_departure") AS t
FROM "${opt.schema}".arrivals_departures, date_min_max
WHERE date <= date_min_max.min
ORDER BY t_departure ASC
LIMIT 1
WHERE date <= (SELECT min FROM date_min_max)
),
min_arr AS (
SELECT t_arrival AS t
SELECT min("t_arrival") AS t
FROM "${opt.schema}".arrivals_departures, date_min_max
WHERE date <= date_min_max.min
ORDER BY t_arrival ASC
LIMIT 1
WHERE date <= (SELECT min FROM date_min_max)
),
max_dep AS (
SELECT t_departure AS t
SELECT min("t_departure") AS t
FROM "${opt.schema}".arrivals_departures, date_min_max
WHERE date >= date_min_max.max
ORDER BY t_departure DESC
LIMIT 1
WHERE date >= (SELECT max FROM date_min_max)
),
max_arr AS (
SELECT t_arrival AS t
SELECT min("t_arrival") AS t
FROM "${opt.schema}".arrivals_departures, date_min_max
WHERE date >= date_min_max.max
ORDER BY t_arrival DESC
LIMIT 1
WHERE date >= (SELECT max FROM date_min_max)
)
SELECT
least(min_dep.t, min_arr.t) as min,
Expand Down

0 comments on commit 6f8c66a

Please sign in to comment.