apex-quick
Quick Flow for simple fixes - Single expert handles explore, code, review, and validate in one pass. Inspired by BMAD Barry.
Optimize Prisma queries with automated analysis, N+1 detection, index recommendations, and performance patterns based on official documentation
> /plugin marketplace add fusengine/agentsHow it fires
How this command gets triggered: by you, by Claude, or both.
/prisma-optimizeContext preview
What this command does when you run it.
Optimize Prisma queries with automated analysis, N+1 detection, index recommendations, and performance patterns based on official documentation
description: Optimize Prisma queries with automated analysis, N+1 detection, index recommendations, and performance patterns based on official documentation
Automatically analyzes and optimizes your Prisma queries by detecting performance issues, N+1 queries, missing indexes, and proposing solutions based on official Prisma documentation 2024-2025.
---
> Use research-expert to fetch official Prisma documentation
**Goals**:
**Actions**:
**Query Focus**:
"Prisma Optimize best practices, N+1 detection, query optimization patterns, index recommendations, select vs include, relationLoadStrategy"
**Deliverable**: Prisma optimization guide with verified methods
---
> Use explore-codebase to analyze existing Prisma setup
**Goals**:
**Actions**:
**Deliverable**: Map of Prisma queries and potential issues
---
After exploration, systematically analyze:
**Detected Pattern**:
// β Anti-pattern detected
const users = await prisma.user.findMany()
users.forEach(async (user) => {
const posts = await prisma.post.findMany({ where: { authorId: user.id } })
})**Recommended Solutions**:
1. **`include`** (Simple):
const users = await prisma.user.findMany({ include: { posts: true } })2. **`relationLoadStrategy: "join"`** (Performant):
const users = await prisma.user.findMany({
relationLoadStrategy: "join",
include: { posts: true }
})---
**Detected Pattern**:
// β Queries on unindexed columns
await prisma.user.findFirst({ where: { name: "Marc" } })**Solution**:
model User {
id Int @id
name String
@@index([name]) // β
Add index
}---
**Detected Pattern**:
// β Fetches all fields unnecessarily
await prisma.user.findMany({ include: { posts: true } })**Solution**:
// β
Select only necessary fields
await prisma.user.findMany({
select: {
id: true,
email: true,
posts: { select: { title: true } }
}
})---
**If desired, install official extension**:
npm install @prisma/extension-optimize
**Configuration**:
import { PrismaClient } from '@prisma/client'
import { withOptimize } from '@prisma/extension-optimize'
const prisma = new PrismaClient().$extends(
withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY })
)---
For each detected issue, propose and implement solutions:
1. **Refactor N+1 queries** β Use `include` or `relationLoadStrategy` 2. **Add missing indexes** β Modify `schema.prisma` with `@@index` 3. **Optimize selects** β Replace with targeted `select` 4. **Limit results** β Add `take`/`skip`
---
> Use sniper to ensure zero linter errors
**Goals**:
**Actions**:
npx prisma validate npx prisma format npm run lint npm run type-check
**Deliverable**: Optimized code with zero errors
---
Generate structured report with:
# Prisma Optimization Report ## π Detected Issues - [X] N+1 Queries: 3 occurrences - [X] Missing Indexes: 5 columns - [X] Overfetching: 2 queries ## β Applied Solutions 1. Refactored users.service.ts with `include` 2. Added indexes on User.name, Post.title 3. Optimized queries with targeted `select` ## π Estimated Performance Gains - Reduced 15 β 3 SQL queries - Queries ~70% faster (estimated) - Network load reduced by ~40% ## π― Additional Recommendations - Enable Prisma Optimize for monitoring - Add performance logs in development - Consider caching with Accelerate
---
**Arguments**: No arguments required
**Example Usage**:
**Notes**:
A plugin ecosystem that turns Claude Code into a supervised, multi-agent development environment.
Repo: fusengine/agents
Quick Flow for simple fixes - Single expert handles explore, code, review, and validate in one pass. Inspired by BMAD Barry.
APEX Methodology - The systematic Analyze-Plan-Execute-eLicit-eXamine approach for intelligent development. Reduces hallucination and defect risk throughβ¦
Memory optimization - removes duplicates, consolidates knowledge, and cleans memory banks for better performance.
Auto-generate Pull Request with comprehensive description, test plan, and changelog. Uses gh CLI for creation.
Comprehensive codebase investigation using research-expert for documentation, explore-codebase for structure, and deep analysis. Perfect for understandingβ¦
Systematic Explore-Plan-Code-Test methodology for structured development. Ensures comprehensive approach to feature implementation.