Individual skill
django-orm-query-optimization
Optimize Django ORM query loading by fixing N+1 queries, duplicate related-object queries, over-fetching, serializer/template query loops, and inappropriate select_related, prefetch_related, only, or defer usage. Use when a Django page, API, admin view, template, serializer, or queryset issues too many queries or loads more model data than needed.
plugins/LVTD-LLC/skills/skills/django-orm-query-optimization/SKILL.md
Source commit d780783eba4ecc7c8b9429f95c9362df95f07c61
What was checked
- Matches the observed repository HEAD
- Yes
- Scanner rules are current
- Yes
- Repository scan complete
- No
- Skill scan complete
- No
- Observed behavior
- Network or broad shell
- Last checked
- Nov 4, 2026
These are observations at the recorded commit, not a guarantee of safety. Review the source before running it.
Install this skill
Choose an agent in your Stack or copy a command below. Commands fetch the pinned commit and copy only this skill directory. Existing destinations are refused. Copying a command does not install anything.
An install command is unavailable: current rules, complete repository and skill scans, an eligible behavior level and a permitted license are required.
Repository context
- Repository stars (not skill ratings)
- 1,533
- Repository last updated
- Nov 6, 2026
- License
- Apache-2.0
Observed agent integration: No specific integration evidence. Standard SKILL.md installation does not imply verified compatibility.
- ai-coding Repository topic
- awesome Repository topic
- awesome-list Repository topic
- codex Repository topic
- codex-plugins Repository topic
- openai Repository topic
- codex-skill Repository topic
- codex-skills Repository topic
- marketplace Repository topic
- codex-marketplace Repository topic
- django,orm,querysets,performance,n-plus-one Declared skill tag
- data Derived category
- engineering Derived category
- engineering-web Derived category
Files and excerpt
File metadata and permitted, redacted excerpts come from the recorded scan. Source links are pinned to that commit.
Browse files
SKILL.mdcore · 2,598 bytesreferences/relationship-and-column-loading.mddoc · 2,380 bytes
Read excerpt
# Django ORM Query Optimization
Use this skill for query-count and object-loading problems. The usual target is an N+1 pattern where each rendered row or serialized object triggers more database work.
## Workflow
1. Prove the query pattern.
- Capture query count and duplicate SQL for the slow path.
- Identify the loop, serializer field, template access, admin display, or model property triggering related queries.
2. Choose the loading strategy.
- Use `select_related()` for single-valued relationships: `ForeignKey` and `OneToOneField`.
- Use `prefetch_related()` for many-valued relationships: reverse FK and many-to-many.
- Use `Prefetch()` when the related queryset needs filters, ordering, annotations, or nested `select_related()`.