Agent skill
slow-query-detector
Detect slow queries and performance issues in Entity Framework Core codebases. Use when analyzing database performance, finding N+1 queries, identifying missing indexes, reviewing repository patterns, or optimizing EF Core queries. Triggers on requests like "find slow queries", "check for N+1 problems", "analyze database performance", "review query performance", or "optimize EF Core queries".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/slow-query-detector
SKILL.md
Slow Query Detector
Analyze EF Core codebases to detect slow queries and performance anti-patterns.
Quick Start
-
Run the analysis script to scan for common issues:
bashpython3 .claude/skills/slow-query-detector/scripts/analyze_efcore.py src -
Review detected issues by severity (Critical > Warning > Info)
-
For each issue, check the suggested fix in references/patterns.md
Detection Workflow
Step 1: Automated Scan
Run the analysis script on the repository:
python3 .claude/skills/slow-query-detector/scripts/analyze_efcore.py src
The script detects:
- N+1 query patterns (loops with await queries)
- ToListAsync followed by in-memory operations
- Missing AsNoTracking on read-only queries
- Unbounded queries (no Take/Skip)
Step 2: Manual Review
After automated scan, manually check:
- Query Handlers - Search for
QueryHandler.csfiles and review foreach loops - Repository Methods - Check for methods that load all records
- Include Chains - Look for missing
.Include()calls
Use grep patterns:
# Find foreach with await inside
grep -rn "foreach.*await" --include="*.cs"
# Find ToListAsync followed by LINQ
grep -rn "ToListAsync.*\." --include="*.cs"
# Find queries without AsNoTracking
grep -rn "await.*context\." --include="*.cs" | grep -v "AsNoTracking"
Step 3: Validate with EF Core Logging
Enable query logging in development to capture actual SQL:
// In Program.cs or DbContext configuration
optionsBuilder
.UseNpgsql(connectionString)
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
Common Patterns & Fixes
See references/patterns.md for detailed patterns including:
- N+1 Query Problem (Critical)
- Memory-based Aggregation (Critical)
- Missing Index Hints (Warning)
- Unbounded Result Sets (Warning)
Project-Specific Checks
For this university management system:
Known Issue Locations
- GetStudentEnrollmentsQueryHandler - N+1 problem fetching course offerings per enrollment
- SelectCourseOfferingsBySemesterQueryHandler - N+1 problem fetching courses per offering
- CourseOfferingRepository.GetNextOfferingIdAsync - Loads all records for Max calculation
- ClassSessionRepository.GetNextSessionIdAsync - Loads all records for Max calculation
Repository Pattern Review
Check all *Repository.cs files in:
src/StudentRegistrations/Infrastructure/Persistence/Repositories/src/Enrollments/Infrastructure/Persistence/Repositories/src/Attendance/Infrastructure/Persistence/Repositories/
Index Verification
Review index definitions in:
src/*/Infrastructure/Persistence/Configurations/*Configuration.cssrc/*/Infrastructure/Persistence/Migrations/*.sql
Resources
scripts/
analyze_efcore.py- Automated scanner for EF Core anti-patterns
references/
patterns.md- Detailed slow query patterns with examples and fixes
Didn't find tool you were looking for?