Skip to content

Commit 37ba617

Browse files
committed
Redirected the realtime hourly queue update to the new table
1 parent 0016d3d commit 37ba617

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

ingest/fetch_ingest_full.sql

+25-6
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,31 @@ SET datetime_last = GREATEST(sensors_rollup.datetime_last, EXCLUDED.datetime_las
832832

833833

834834
-- Update the table that will help to track hourly rollups
835-
INSERT INTO hourly_stats (datetime)
836-
SELECT date_trunc('hour', datetime)
837-
FROM temp_inserted_measurements
838-
GROUP BY 1
839-
ON CONFLICT (datetime) DO UPDATE
840-
SET modified_on = now();
835+
--INSERT INTO hourly_stats (datetime)
836+
-- SELECT date_trunc('hour', datetime)
837+
-- FROM temp_inserted_measurements
838+
-- GROUP BY 1
839+
--ON CONFLICT (datetime) DO UPDATE
840+
--SET modified_on = now();
841+
842+
WITH inserted_hours AS (
843+
-- first we group things, adding an hour to make it time-ending after truncating
844+
SELECT datetime + '1h'::interval as datetime
845+
, utc_offset(datetime + '1h'::interval, tz.tzid) as tz_offset
846+
FROM temp_inserted_measurements m
847+
JOIN sensors s ON (s.sensors_id = m.sensors_id)
848+
JOIN sensor_systems sy ON (s.sensor_systems_id = sy.sensor_systems_id)
849+
JOIN sensor_nodes sn ON (sy.sensor_nodes_id = sn.sensor_nodes_id)
850+
JOIN timezones tz ON (sn.timezones_id = tz.timezones_id)
851+
GROUP BY 1, 2
852+
)
853+
INSERT INTO hourly_data_queue (datetime, tz_offset)
854+
SELECT as_utc_hour(datetime, tz_offset), tz_offset
855+
FROM inserted_hours
856+
GROUP BY 1, 2
857+
ON CONFLICT (datetime, tz_offset) DO UPDATE
858+
SET modified_on = now();
859+
841860

842861
-- update the table that will track the daily exports
843862
WITH e AS (

0 commit comments

Comments
 (0)