django-query-optimizer

Optimize Django ORM queries to eliminate N+1 problems and suggest indexes.

1|Updated Mar 17, 2025
Ready to run
npx skills add https://github.com/MaciWP/CV_Astro --skill django-query-optimizer
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: django-query-optimizer
Source: https://github.com/MaciWP/CV_Astro/tree/main/.claude/skills/django-query-optimizer
Command: npx skills add https://github.com/MaciWP/CV_Astro --skill django-query-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires Django, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill identifies and resolves common performance bottlenecks in Django applications by optimizing ORM queries, eliminating N+1 problems, and suggesting proper indexing for faster database interactions.

Core Features & Use Cases

  • N+1 Query Detection & Fixes: Automatically find and fix inefficient N+1 query patterns using select_related and prefetch_related for efficient data fetching.
  • Indexing Strategies: Recommend and generate optimal database indexes for frequently queried fields and complex WHERE or ORDER BY clauses.
  • Use Case: Analyze a slow Django API endpoint that lists users and their associated posts, then optimize the query to fetch all data in a single database hit, or generate a migration for a composite index.

Quick Start

Optimize the following Django ORM query to avoid N+1: for user in User.objects.all(): print(user.posts.count()).