Agent skill
ecto:n1-check
Scan Ecto code for N+1 anti-patterns — Repo calls in loops, missing preloads, unpreloaded associations. Use when excessive queries reported or wanting an N+1 audit.
Install this agent skill to your Project
npx add-skill https://github.com/oliver-kriska/claude-elixir-phoenix/tree/main/plugins/elixir-phoenix/skills/n1-check
SKILL.md
N+1 Query Detection
Identify and fix N+1 query anti-patterns in Ecto/Phoenix applications.
Iron Laws - Never Violate These
- Never access associations without preload - Always preload before
Enum.map - No Repo calls inside loops - Restructure to batch queries
- Preload at context boundary - Load associations in context, not controllers/views
- Use joins for filtering - Use
join+preloadwhen filtering by association
Detection Patterns
Pattern 1: Enum.map with Repo
# BAD: N+1 queries
users
|> Enum.map(fn user -> Repo.get(Order, user.order_id) end)
# GOOD: Single query with preload
users
|> Repo.preload(:orders)
Pattern 2: Association Access Without Preload
# BAD: Lazy loading triggers N queries
for user <- users do
user.posts # Triggers query for each user!
end
# GOOD: Eager load first
users = Repo.all(User) |> Repo.preload(:posts)
for user <- users do
user.posts # Already loaded
end
Pattern 3: Nested Association Access
# BAD: N+1 for nested associations
user.posts |> Enum.map(fn post -> post.comments end)
# GOOD: Nested preload
Repo.preload(user, posts: :comments)
Quick Detection Commands
Use Grep with context lines (-B 5 -A 5) to find Enum.map near Repo. calls in lib/**/*.ex.
Use Grep to find association access patterns (.posts, .comments, .orders) in lib/**/*.ex.
Use Grep with context (-B 3) to find Repo.get or Repo.one near loop patterns (for, Enum) in lib/**/*.ex.
Analysis Command
For a context module, run:
Use Grep to find all Repo. calls in the context module, then verify each has appropriate preloads.
Then verify each query has appropriate preloads.
References
For detailed patterns, see:
${CLAUDE_SKILL_DIR}/references/preload-patterns.md- Efficient preloading strategies${CLAUDE_SKILL_DIR}/references/query-optimization.md- Query batching techniques
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
lab:autoresearch
Self-improving loop for plugin skills. Reads program.md, proposes one mutation per iteration, evaluates against deterministic scorer, keeps improvements via git, reverts failures. Targets weakest skill+dimension. Use with /loop for overnight runs.
promote
Generate X/Twitter release promotion posts with ASCII tables and CodeSnap rendering. Use when writing release posts, promotion tweets, plugin announcements, or preparing social media content for new versions.
skill-monitor
Analyze skill effectiveness across sessions. Computes per-skill metrics (action rate, friction, outcomes), identifies degrading skills, and generates improvement recommendations. Requires session-scan data in metrics.jsonl.
session-trends
Analyze trends across session metrics. Computes windowed aggregates, deltas, and compares against MEMORY.md findings. Use periodically for progress tracking.
cc-changelog
CONTRIBUTOR TOOL - Track CC changelog, extract new versions since last check, analyze impact on plugin (breaking changes, opportunities, deprecations). Run periodically or before releases. NOT part of the distributed plugin.
session-scan
Compute metrics for Claude Code sessions. Discovers via ccrider, filters trivial, computes friction/opportunity/fingerprint scores. Use for broad session triage.
Didn't find tool you were looking for?