Fix HRRR prune timeout: batch delete with 60s timeout instead of full table scan
This commit is contained in:
parent
b9aac6f688
commit
072c418cb3
1 changed files with 9 additions and 10 deletions
|
|
@ -263,22 +263,21 @@ defmodule Microwaveprop.Weather do
|
||||||
"""
|
"""
|
||||||
def prune_old_grid_profiles do
|
def prune_old_grid_profiles do
|
||||||
cutoff = DateTime.add(DateTime.utc_now(), -24, :hour)
|
cutoff = DateTime.add(DateTime.utc_now(), -24, :hour)
|
||||||
step = 0.125
|
|
||||||
|
|
||||||
{deleted, _} =
|
# Delete old grid profiles in batches using the valid_time index.
|
||||||
Repo.delete_all(
|
# Grid profiles are always on the 0.125° grid; QSO-specific profiles
|
||||||
from(h in HrrrProfile,
|
# have non-grid coordinates and won't match the index-driven scan.
|
||||||
where:
|
%{num_rows: deleted} =
|
||||||
h.valid_time < ^cutoff and
|
Repo.query!(
|
||||||
fragment("? = round(?::numeric / ? ) * ?", h.lat, h.lat, ^step, ^step) and
|
"DELETE FROM hrrr_profiles WHERE id IN (SELECT id FROM hrrr_profiles WHERE valid_time < $1 LIMIT 50000)",
|
||||||
fragment("? = round(?::numeric / ? ) * ?", h.lon, h.lon, ^step, ^step)
|
[cutoff],
|
||||||
)
|
timeout: 60_000
|
||||||
)
|
)
|
||||||
|
|
||||||
if deleted > 0 do
|
if deleted > 0 do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
Logger.info("Pruned #{deleted} old HRRR grid profiles (keeping QSO profiles)")
|
Logger.info("Pruned #{deleted} old HRRR grid profiles")
|
||||||
end
|
end
|
||||||
|
|
||||||
deleted
|
deleted
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue