queryset-optimizer

queryset-optimizer is a skill for Codex from ragnarok22/agent-skills. It costs 84 tokens per session (879 once invoked), scanned A, original, MIT.

A performance checker for Django's ORM, the part of Django that reads and writes database records using Python objects. It looks for repeated database queries, missing related-data loading, and possible missing indexes.

In plain words
What is it for?
Use it to audit views, serializers, background tasks, or other read-heavy Django code through runtime query capture when possible and targeted static scans when it is not.
Why use it?
It helps explain why Django endpoints are making too many database queries and provides evidence-based fixes with an expected effect on query counts.

Skill for Codex

Written for Codex: agents/openai.yaml present.

Good fit Use it to audit views, serializers, background tasks, or other read-heavy Django code through runtime query capture when possible and targeted static scans when it is not.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ragnarok22/agent-skills/queryset-optimizer
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ragnarok22/agent-skills --skill queryset-optimizer
Clone the repo
git clone --depth 1 https://github.com/ragnarok22/agent-skills

Made for: Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for queryset-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/skills/ragnarok22/agent-skills/queryset-optimizer.svg)](https://agentmods.dev/skills/ragnarok22/agent-skills/queryset-optimizer)
Your own site
<a href="https://agentmods.dev/skills/ragnarok22/agent-skills/queryset-optimizer"><img src="https://agentmods.dev/badge/skills/ragnarok22/agent-skills/queryset-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 84 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 879 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00084 $0.00879
Opus 5 $0.00042 $0.00439
Sonnet 5 $0.00017 $0.00176
Haiku 4.5 $0.00008 $0.00088

Measured 8d ago against content hash 97028a365568, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

queryset-optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/queryset-optimizer/SKILL.md · 134 lines

How it starts

The opening of the file, as written. The whole thing — 134 lines — stays where its author put it; the contents beside it link to each section on GitHub.

QuerySet Optimizer

Audit Django query performance with deterministic checks and evidence-backed recommendations.

Workflow

Step 1: Set scope and baseline target

  1. Locate the Django backend root (directory containing manage.py).
  2. Define the optimization target:
    • endpoint or view
    • serializer
    • background task
    • repeated ORM hotspot from profiling data
  3. If target is unknown, scan all app directories and prioritize read-heavy paths first (list endpoints, feed pages, reports).

Step 2: Capture runtime query evidence (preferred)

Collect at least one measurable baseline for the target before changing code.

Open Django shell:

uv run manage.py shell 2>/dev/null || python manage.py shell

Then capture query count for one representative code path:

from django.db import connection
from django.test.utils import CaptureQueriesContext

with CaptureQueriesContext(connection) as ctx:
    # Execute the target path, for example evaluating the target queryset.
    list(qs)

print(f"queries={len(ctx.captured_queries)}")

If runtime capture is not feasible, continue with static analysis and mark runtime validation as not evaluated.

Step 3: Run static scan

Read references/antipatterns.md for rule IDs, severity, search commands, and fix patterns.

For each rule:

  1. Run the suggested search command.
  2. Manually validate each candidate.
  3. Exclude false positives (tests, migrations, fixtures, one-off scripts) unless explicitly relevant.
  4. Record confirmed findings with:
    • ID
    • Severity
    • File and line number
    • Evidence (1-2 lines)
    • Fix recommendation
    • Expected impact (query count, memory, latency, or lock time)

Step 4: Score

Start from 100 and deduct points per confirmed finding:

Severity Deduction
High -8
Medium -5
Low -2

Rules:

  • Floor score at 0.
  • Cap duplicate deductions for each rule ID to 3 findings.
  • Deduct only for confirmed findings.
  • Add +5 bonus (max 100) when before/after query counts are measured for at least one hotspot.

Read the full file on GitHub · 134 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 134 lines · 84 tokens per session scan A 97028a365568

Subscribe to this mod's changes

queryset-optimizer is a skill published in the GitHub repository ragnarok22/agent-skills (5 stars, last pushed 2mo ago), licensed MIT. It adds 84 tokens to every session and 879 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

fix-failing-tests

Diagnose a failing test in the googleapis/mcp-toolbox repo and land a fix by reasoning from the actual error: read the failure, reproduce it, shrink it until the cause is forced into the open, then fix the cause. Use this whenever a test or CI job is red, a build breaks after a change, many packages fail at once, or a…

googleapis/mcp-toolbox · 87 tokens

triage-issues

Triage GitHub issues in the googleapis/mcp-toolbox repo: propose the correct labels (type / priority / product / status), check for duplicates, verify a bug has enough info to act on, and draft a triage comment. Use whenever a maintainer asks you to triage, label, categorize, prioritize, or "look at" an issue (or a…

googleapis/mcp-toolbox · 164 tokens

postgresql-indexing

PostgreSQL indexing best practices for Prowler: index design, partial indexes, partitioned table indexing, EXPLAIN ANALYZE validation, concurrent operations, monitoring, and maintenance. Trigger: When creating or modifying PostgreSQL indexes, analyzing query performance with EXPLAIN, debugging slow queries, reviewing…

prowler-cloud/prowler · 108 tokens

graphjin-eval

Create, extend, run, baseline, and diagnose GraphJin agent evaluations through the graphjin eval CLI.

dosco/graphjin · 27 tokens

axiom-audit-grdb-performance

Use when the user mentions GRDB performance review, slow GRDB queries, app-group database setup audit, a ValueObservation that stopped updating, or pre-release GRDB scan.

CharlesWiltgen/Axiom · 43 tokens

django-perf-review

Django performance code review. Use when asked to "review Django performance", "find N+1 queries", "optimize Django", "check queryset performance", "database performance", "Django ORM issues", or audit Django code for performance problems.

getsentry/skills · 55 tokens