diff --git a/lib/microwaveprop/weather.ex b/lib/microwaveprop/weather.ex index 5b003727..3dd58492 100644 --- a/lib/microwaveprop/weather.ex +++ b/lib/microwaveprop/weather.ex @@ -434,12 +434,18 @@ defmodule Microwaveprop.Weather do def analyze_all(opts \\ []) do skip_recent = Keyword.get(opts, :skip_recent_seconds, 6 * 3600) + # `last_autoanalyze` is only set by the autovacuum daemon; + # `last_analyze` is set by manual ANALYZE (including our Task + # below). Take the newer of the two — otherwise a re-run within + # `skip_recent` would re-analyze everything we just did. q = """ SELECT relname FROM pg_stat_user_tables WHERE schemaname = 'public' - AND (last_autoanalyze IS NULL - OR last_autoanalyze < now() - ($1 || ' seconds')::interval) + AND COALESCE( + GREATEST(last_analyze, last_autoanalyze), + 'epoch'::timestamptz + ) < now() - ($1 || ' seconds')::interval ORDER BY n_live_tup ASC """