mcpbeat

Ecto N1 Check

oliver-kriska/claude-elixir-phoenix-ecto-n1-check

Find Ecto N+1 queries and missing preloads. Use only when N+1 is suspected; not for broad database performance.

2k tokens
context cost
the whole folder, loaded on every use
3
files
instructions only
0
copies elsewhere
how many repositories repackaged it
514
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/oliver-kriska/claude-elixir-phoenix --skill ecto-n1-check

What comes with it

6 877 bytes besides the instruction
references/preload-patterns.md
references/query-optimization.md

The instruction itself

9 sections, as written by the author

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 + preload when 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:

  • references/preload-patterns.md - Efficient preloading strategies
  • references/query-optimization.md - Query batching techniques

How to use it

Copy the folder

Take oliver-kriska/claude-elixir-phoenix-ecto-n1-check from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.