Skip to content
Back to skills

Query Optimize

ASecurity

Optimizes database queries - adds indexes, rewrites N+1s, batches requests

  • 10 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 1, 2026
ai-agentsbashdatabase

Security analysis

A100/100

Scanned June 1, 2026

npx -y skills add berkcangumusisik/claude-code-practices --skill query-optimize --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Query Optimize?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Query Optimize
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/berkcangumusisik-query-optimize/badge)](https://www.skillsdirectory.com/skills/berkcangumusisik-query-optimize)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: query-optimize
description: Optimizes database queries - adds indexes, rewrites N+1s, batches requests
argument-hint: [file-path]
user-invocable: true
allowed-tools: Read Grep Glob Edit
effort: medium
---

## Query Optimization

Target: **$1** (or scan `src/` for all DB interactions)

1. Find all database queries:
```bash
grep -rn "\.find\|\.findMany\|\.query\|\.select\|db\.\|prisma\.\|knex\." ${1:-src/} --include="*.ts" | head -40
```

2. Check for N+1 patterns:
```ts
// ❌ N+1: querying inside a loop
for (const user of users) {
  user.posts = await db.posts.findMany({ where: { userId: user.id } })
}

// ✅ Fix: batch with include or Promise.all
const users = await db.users.findMany({ include: { posts: true } })
```

3. Check for missing `select` (over-fetching):
```ts
// ❌ Fetches all 40 columns
await db.users.findMany()

// ✅ Only what's needed
await db.users.findMany({ select: { id: true, name: true, email: true } })
```

4. Propose missing indexes for frequently-filtered columns.

5. Show before/after for each optimization. Apply on confirmation.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…