Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of higher and works with any version of Elixir.
Explanation
Calling Repo.get, Repo.one, or Repo.all inside Enum.map/2 is
an N+1 query — one database round-trip per element.
# bad — N+1 queries
users
|> Enum.map(fn user ->
posts = Repo.all(from p in Post, where: p.user_id == ^user.id)
%{user | posts: posts}
end)
# good — preload in one query
users |> Repo.preload(:posts)Check-Specific Parameters
There are no specific parameters for this check.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.