Fix backfill progress to use exact counts instead of pg_stat estimates

This commit is contained in:
Graham McIntire 2026-04-06 08:54:30 -05:00
parent 0b68cb2d29
commit f4d3773e2b
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -86,6 +86,9 @@ defmodule MicrowavepropWeb.BackfillLive do
defp count_unprocessed do
incomplete = [:pending, :queued, :processing, :failed]
done = [:complete, :unavailable]
total = Repo.one(from(c in Contact, where: not is_nil(c.pos1), select: count()))
terrain =
Repo.one(from(c in Contact, where: c.terrain_status in ^incomplete and not is_nil(c.pos1), select: count()))
@ -96,11 +99,30 @@ defmodule MicrowavepropWeb.BackfillLive do
weather =
Repo.one(from(c in Contact, where: c.weather_status in ^incomplete and not is_nil(c.pos1), select: count()))
iemre =
Repo.one(from(c in Contact, where: c.iemre_status in ^incomplete and not is_nil(c.pos1), select: count()))
all_done =
Repo.one(
from(c in Contact,
where:
not is_nil(c.pos1) and
c.hrrr_status in ^done and
c.weather_status in ^done and
c.terrain_status in ^done and
c.iemre_status in ^done,
select: count()
)
)
%{
terrain: terrain,
hrrr: hrrr,
weather: weather,
total: max(terrain, max(hrrr, weather))
iemre: iemre,
remaining: max(terrain, max(hrrr, max(weather, iemre))),
complete: all_done,
total: total
}
end
@ -268,19 +290,20 @@ defmodule MicrowavepropWeb.BackfillLive do
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 my-6">
<div class="bg-base-200 rounded-box p-4">
<div class="text-xs opacity-60">Enrichment Progress</div>
<div class="text-2xl font-bold">{@unprocessed.total} remaining</div>
<div class="text-2xl font-bold">{@unprocessed.remaining} remaining</div>
<div class="text-xs opacity-60 mt-1">
{@db_stats.totals.contacts - @unprocessed.total} / {@db_stats.totals.contacts} complete
{@unprocessed.complete} / {@unprocessed.total} fully enriched
</div>
<progress
class="progress progress-primary w-full mt-2"
value={@db_stats.totals.contacts - @unprocessed.total}
max={@db_stats.totals.contacts}
value={@unprocessed.complete}
max={@unprocessed.total}
/>
<div class="flex gap-4 mt-2 text-xs opacity-60">
<span>Terrain: {@unprocessed.terrain}</span>
<span>HRRR: {@unprocessed.hrrr}</span>
<span>Weather: {@unprocessed.weather}</span>
<span>Terrain: {@unprocessed.terrain}</span>
<span>IEMRE: {@unprocessed.iemre}</span>
</div>
</div>
<div class="bg-base-200 rounded-box p-4">