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