From 239bf707aac4bfea424d2fe90dd8f31ba46ed21c Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 1 Apr 2026 15:27:11 -0500 Subject: [PATCH] Fix HRRR prune timeout: bound time range for partition pruning --- lib/microwaveprop/weather.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/microwaveprop/weather.ex b/lib/microwaveprop/weather.ex index a400b1f1..d9a032b6 100644 --- a/lib/microwaveprop/weather.ex +++ b/lib/microwaveprop/weather.ex @@ -263,6 +263,9 @@ defmodule Microwaveprop.Weather do """ def prune_old_grid_profiles do cutoff = DateTime.add(DateTime.utc_now(), -24, :hour) + # Bound the scan to recent partitions only (grid profiles are at most ~48h old). + # Without a lower bound, Postgres scans every partition back to 2016. + floor = DateTime.add(DateTime.utc_now(), -72, :hour) # Only delete profiles on the 0.125° propagation grid, preserving QSO-linked # profiles which sit at arbitrary lat/lon positions (HRRR's native ~3km grid). @@ -270,12 +273,12 @@ defmodule Microwaveprop.Weather do Repo.query!( """ DELETE FROM hrrr_profiles - WHERE valid_time < $1 + WHERE valid_time >= $2 AND valid_time < $1 AND (lat * 1000)::int % 125 = 0 AND (lon * 1000)::int % 125 = 0 """, - [cutoff], - timeout: 120_000 + [cutoff, floor], + timeout: 300_000 ) if deleted > 0 do