Repository navigation
fix: resolve CloudTable em 1 query agregada no sync-deployments - #1113
Merged
Merged
Conversation
A resolução de tabela por deployment (introduzida em #1112) fazia uma query de CloudTable por deployment. Com centenas de deployments isso multiplicou os round-trips ao banco o bastante pra estourar o timeout do gateway nginx em produção (POST /admin-tools/sync-deployments/ retornando 504 antes de terminar). Troca por um índice único, montado com uma query no início (_build_cloud_table_index), e troca o loop de save() por tabela por um update() em lote por deployment.
Winzen
force-pushed
the
fix/sync-deployments-cloud-table-nplus1
branch
from
October 7, 2026 22:57
ed9aa7f to
dea41dc
Compare
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto
Depois do merge de #1112,
POST /admin-tools/sync-deployments/passou a estourar o timeout do gateway nginx (504) em produção, confirmado rodando contra prod via o token já usado porset_deployment_schedule_active.Causa: a resolução de tabela por deployment (
_resolve_single_table) fazia uma query deCloudTablepor deployment. Com centenas de deployments, isso multiplicou os round-trips ao banco o bastante pra passar doproxy_read_timeoutdo nginx — confirmado com duas tentativas reais, ambas cortadas em ~61s.Mudança
backend/apps/admin_data_tools/flow_monitoring.py:_build_cloud_table_index(): carrega todos osCloudTablenuma única query, indexados em dois dicts —{(gcp_dataset_id, gcp_table_id): table_id}pro match direto,{gcp_dataset_id: {table_id, ...}}pro fallback monolítico._resolve_single_table_id/_dedicated_table_ids/_resolve_table_ids: agora operam sobre esses dicts em memória (ids, não instâncias deTable) em vez de consultar o banco a cada chamada._sync_deployment: troca o loopfor table in tables: table.save()por um únicoTable.objects.filter(id__in=table_ids).exclude(...).update(flow_schedule_id=record.id)por deployment.Resultado: 1 query de
CloudTablepro sync inteiro (era N, uma por deployment), e 1UPDATEem lote por deployment com tabelas vinculadas (era NSELECT+ NUPDATE, um por tabela).Benefícios
resultsdict idêntico), sem mudança de schema.Test plan
22 testes automatizados (os mesmos de #1112, incluindo os cenários de flow monolítico e exclusão de tabela dedicada) rodando verde contra Postgres real em Docker local, sem alteração nenhuma nos testes — a refatoração é transparente pro comportamento.