Skip to content
Back to skills

Ecto N1 Check

ASecurity

Find Ecto N+1 queries and missing preloads. Use only when N+1 is suspected;

  • 580 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
developmentgoawsdatabaseperformance

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 29, 2026

npx -y skills add oliver-kriska/claude-elixir-phoenix --skill ecto-n1-check --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ecto N1 Check?

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

Security grade badge for Ecto N1 Check
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/oliver-kriska-ecto-n1-check-claude-elixir-phoenix/badge)](https://www.skillsdirectory.com/skills/oliver-kriska-ecto-n1-check-claude-elixir-phoenix)

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: ecto-n1-check
description: Find Ecto N+1 queries and missing preloads. Use only when N+1 is suspected;
  not for broad database performance.
---

# N+1 Query Detection

Identify and fix N+1 query anti-patterns in Ecto/Phoenix applications.

## Iron Laws - Never Violate These

1. **Never access associations without preload** - Always preload before `Enum.map`
2. **No Repo calls inside loops** - Restructure to batch queries
3. **Preload at context boundary** - Load associations in context, not controllers/views
4. **Use joins for filtering** - Use `join` + `preload` when filtering by association

## Detection Patterns

### Pattern 1: Enum.map with Repo

```elixir
# 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

```elixir
# 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

```elixir
# 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

Use Grep to find all `Repo.` calls in a context module, 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

Files in this skill

  • SKILL.md2 KB
  • references/preload-patterns.md2.9 KB
  • references/query-optimization.md3.8 KB

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.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.