Refator scripts/normalize.py::load_all_contracts para streaming #2
Labels
No labels
area/api
area/auth
area/dashboard
area/db
area/frontend
area/llm
area/scrapers
meta
priority/critical
priority/high
priority/low
priority/medium
type/bug
type/feature
type/infra
type/refactor
type/security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
soberania-brasileira/digital#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contexto
A função carrega 4,77M rows de
contratosnum únicocursor.execute() + fetchall(). RSS Python explode no LXC de 8 GiB — em 2026-04-28 causou OOM-thrash com sshd/nginx/postgres ficando mudos por horas.Reproduce
Solução
fetchall()por server-side cursor:conn.cursor("named", withhold=False)+cur.itersize = 10000generate_uniao_jsons,generate_estados_json,generate_municipios_jsonpara SQL agregado (o quegenerate_dashboard_jsonjá faz)generate_municipios_jsonfazUPPER(unaccent(TRIM(municipio)))por município (não-sargável, lentíssimo) — substituir por chave normalizada na ingestãoMemoryMax=2G) como guarda-chuvaCritério de aceite
python scripts/normalize.pyem produção sem ultrapassar 500 MB RSS e MemAvailable nunca abaixo de 1 GBWorkaround atual
/tmp/fast_regen_dashboard.py(criado em 2026-04-29) regera só headline + séries dodashboard.jsonem 5s, RSS < 100 MB. Mas pula estados/municípios/uniao.