Otimização de queries e resolução de gargalos de performance em Contas a Pagar#2
Open
samueljml wants to merge 3 commits intolucrorural:mainfrom
Open
Otimização de queries e resolução de gargalos de performance em Contas a Pagar#2samueljml wants to merge 3 commits intolucrorural:mainfrom
samueljml wants to merge 3 commits intolucrorural:mainfrom
Conversation
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.
Esta PR melhora a performance da listagem de Contas a Pagar e Notas Fiscais e padroniza respostas da API.
Otimizações de performance
Para reduzir o tempo de resposta e otimizar o consumo de recursos, foram implementadas as seguintes técnicas:
.annotate(total_notas=Count('notas_fiscais'))para realizar cálculos agregados diretamente no banco de dados..only()na listagem para buscar apenas os campos estritamente necessários, reduzindo o tráfego de dados entre DB e aplicação..prefetch_related('notas_fiscais')no endpoint de detalhes, otimizando a consulta de relacionamentos Many-to-Many e eliminando múltiplas queries redundantes.statuspara buscas precisas.data_vencimento,valoretotal_notas.Decisões de arquitetura e segurança
@cache_page) nos endpoints financeiros. Dada a natureza crítica de Contas a Pagar, a precisão e a consistência em tempo real são prioritárias sobre a economia de processamento que o cache ofereceria.CustomExceptionHandlerque retorna mensagens estruturadas, facilitando o consumo e o tratamento de exceções pelo Front-end.📊 Validação de Performance (
benchmark.py)Para validar as hipóteses de otimização e garantir a entrega dos requisitos, foi desenvolvido um script de benchmark: