django-db-performance
Diagnose and improve slow Django database-backed endpoints with evidence-first profiling, query-plan review, index selection, ORM loading fixes, batching, database-side computation, materialized views, and pagination choices. Use when a Django view, API, job, report, queryset, or database query is slow and the right optimization path is not obvious.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- django-db-performance
- license
- MIT
- metadata
- { "tags": "django,database,performance,orm,profiling", "version": "0.1.0", "category": "Django", "displayName": "Django DB Performance" }
- description
- Diagnose and improve slow Django database-backed endpoints with evidence-first profiling, query-plan review, index selection, ORM loading fixes, batching, database-side computation, materialized views, and pagination choices. Use when a Django view, API, job, report, queryset, or database query is slow and the right optimization path is not obvious.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 1
- 参考文档references/diagnostic-flow.md2.6 KB
03 SKILL.md 正文
Django DB Performance
Use this as the orchestration skill for Django database performance work. Start with measured evidence, reproduce the slow path, and route to the smallest optimization that changes the measured bottleneck.
Core Workflow
-
Capture the symptom.
- Identify the exact endpoint, command, task, report, or queryset.
- Record current wall-clock time, query count, slow SQL, database backend, data volume, and Django version.
- Keep the original request parameters or fixture that reproduces the issue.
-
Profile before changing code.
- Use APM traces, database slow-query logs, Django Debug Toolbar,
connection.queries, or targeted logging. - If the expensive query is known, use
QuerySet.explain()or databaseEXPLAIN. - For API endpoints, profile serializers and permission checks as well as querysets.
- Use APM traces, database slow-query logs, Django Debug Toolbar,
-
Classify the dominant problem.
- Many repeated similar queries: use
django-orm-query-optimization. - One or two expensive SQL statements: use
django-query-plan-readinganddjango-index-design. - Large memory use or long loops over querysets: use
django-queryset-batch-processing. - Python loops computing counts, totals, flags, or latest related rows: use
django-db-side-computation. - Slow aggregate/report query that is acceptable when stale: use
django-materialized-views. - Slow or inconsistent list pages: use
django-pagination-performance. - Unclear evidence: use
django-query-profiling.
- Many repeated similar queries: use
-
Apply one change at a time.
- Prefer the narrowest change with a clear expected effect.
- Avoid adding indexes, prefetches, or materialized views speculatively.
- Confirm that the optimization helps real production-like data, not only tiny fixtures.
-
Verify and document the result.
- Re-run the same request or command with the same parameters.
- Compare query count, total DB time, wall-clock time, memory, and query plan.
- Keep before/after evidence in the PR or final report.
See diagnostic-flow.md for routing checklists, common symptoms, and before/after evidence templates.
Modern Django Notes
- Prefer
QuerySet.explain()for ORM query plans before dropping to rawEXPLAIN. - Prefer native Django/PostgreSQL migration operations such as
AddIndexConcurrentlyover hand-written concurrent index SQL when they fit. - Prefer ORM expressions,
Subquery,Exists,Window,GeneratedField, anddb_defaultwhen they make database work explicit and portable enough. - Treat every backend-specific optimization as conditional on the project database. PostgreSQL patterns do not automatically apply to MySQL, MariaDB, SQLite, or Oracle.
Verification
- Show the slow path is still functionally correct.
- Show the measured bottleneck improved.
- Show the optimization did not create a worse query, stale data bug, write-path regression, or memory spike.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.