About this project
django-query-optimizer is a tool designed to analyze and optimize Django ORM performance. It identifies common database bottlenecks such as N+1 queries, duplicate SQL execution, and slow queries, providing concrete suggestions for fixes (e.g., using select_related() or prefetch_related()).
Key capabilities include:
- Query Collection: A thread-safe context manager and HTTP middleware to capture SQL queries, execution duration, and Python stack traces.
- Specialized Detectors: Built-in analysis for general slow/duplicate queries, N+1 patterns, ForeignKey lookup repetitions, and DRF serializer-specific N+1 issues.
- Integration Points:
- Django Admin: A dashboard to view session lists and top slow queries.
- pytest: A plugin providing a `--query-analysis` flag and a `query_collector` fixture for asserting query counts and performance in tests.
- VS Code: Support for SARIF 2.1.0 output to surface diagnostics as inline warnings in the editor.
- Scoring: A health scoring system (0-100) with letter grades (A-F) to quantify ORM efficiency.
The tool is intended for development environments and provides a public API for custom analysis via QueryCollector and QueryAnalyzer.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.