elixir-phoenix-n1-check
Scan Ecto code for N+1 queries and missing preloads.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Scan Ecto code for N+1 queries and missing preloads.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Recommend the right `$elixir-phoenix-*` skill for the current task.
Elixir/Phoenix: Review lifecycle, state-machine, Oban, persistence, pause/resume, retry, and restart-sensitive changes before commit, push, or PR. Use for concurrency-sensitive runtime work to produce explicit blocking vs optional findings, require durability checks, and verify smoke plus restart resilience when applicable.
Capture a solved Phoenix problem as a reusable solution doc.
Audit LiveView assigns for memory bloat, dead assigns, and stream candidates.
Audit project health across architecture, security, performance, tests, and deps.
Analyze Phoenix context boundaries and coupling with `mix xref`.
| name | elixir-phoenix-n1-check |
| description | Scan Ecto code for N+1 queries and missing preloads. |
| metadata | {"short-description":"Audit Ecto queries for N+1s"} |
Identify and fix N+1 query anti-patterns in Ecto/Phoenix applications.
Enum.mapjoin + preload when filtering by association# 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)
# 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
# BAD: N+1 for nested associations
user.posts |> Enum.map(fn post -> post.comments end)
# GOOD: Nested preload
Repo.preload(user, posts: :comments)
Use rg with context lines (-B 5 -A 5) to find Enum.map near Repo. calls in lib/**/*.ex.
Use rg to find association access patterns (.posts, .comments, .orders) in lib/**/*.ex.
Use rg with context (-B 3) to find Repo.get or Repo.one near loop patterns (for, Enum) in lib/**/*.ex.
For a context module, run:
Use rg to find all Repo. calls in the context module, then verify each has appropriate preloads.
Then verify each query has appropriate preloads.
For detailed patterns, see:
references/preload-patterns.md - Efficient preloading strategiesreferences/query-optimization.md - Query batching techniques