跳到主要内容
知仓学习社ZHICANG

django-query-profiling

Find the Django ORM code and request path responsible for slow SQL by using APM traces, slow query logs, Django Debug Toolbar, query logging, and lo…

不碰外部(只输出文字)无严重或高危命中hashgraph-online/awesome-codex-plugins

它会碰到什么

扫了多少2 个文本文件,5 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Django Query Profiling

Use this skill to turn a vague slow-Django report into a specific queryset, SQL statement, and reproducible scenario.

Workflow

  1. Start from the user-visible slow path.
  • Record the URL, API action, background task, management command, or report.
  • Capture request parameters, user or tenant shape, pagination state, and data volume.
  1. Collect production or staging evidence.
  • Prefer APM transaction traces when available.
  • Use database slow-query logs for SQL that is slow independent of Python.
  • Use Django Debug Toolbar for server-rendered pages in local development.
  • For APIs or jobs, add targeted query logging around the suspicious block.
  1. Map SQL back to Django code.
  • Search model table names and column names.
  • Inspect view get_queryset(), serializer fields, template loops, managers, model properties, and signal handlers.
  • Check whether related-object access happens after the initial queryset was evaluated.
  1. Reproduce locally or in a safe shell.
  • Use production-like row counts when possible.
  • Disable unrelated instrumentation and debug-only middleware when measuring.
  • Keep a repeatable script, test, or shell snippet that exercises the slow path.
  1. Route the fix.
  • Query count issue: use django-orm-query-optimization.
  • One slow SQL statement: use django-query-plan-reading.
  • Large loops or writes: use django-queryset-batch-processing.

See [tooling-and-reproduction.md](references/tooling-and-reproduction.md) for concrete profiling snippets and pitfalls.

Good Evidence

  • Query count before/after for the specific path.
  • The slow SQL or normalized SQL fingerprint.
  • Stack or code pointer that explains where the SQL originates.
  • Timing from the same environment and representative data shape.

Verification

Do not finish profiling with only a hunch. Finish with a named queryset, code path, and command or request that another agent can re-run.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。