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
Avoid calling Repo from inside repeated execution.
This check follows callback execution rather than lexical nesting. It
covers callback positions on Enum and Stream operations,
Task.async_stream/2 and its related Task and Task.Supervisor variants,
and for comprehensions. Reads, writes, preload/reload operations, and
transaction or connection entry are all reportable because each can cause
repeated database work.
Execution model
For lazy streams and async streams, a callback is reportable because it runs once per consumed element even though it does not run when the stream is constructed.
Expressions evaluated once at the top level are not reported. These
include loop inputs, initial values and options, callback construction,
the first for generator's right-hand side, and once-only start,
finalizer, and fallback callbacks. Such expressions remain reportable
when an enclosing repeated boundary causes them to execute repeatedly.
Matching and limitations
Repo matching is syntactic and exact: Repo and literal module paths
ending in Repo are recognized. Helper modules, dynamic module
expressions, and fuzzy names are not.
Custom aliases such as DB, callback variables or factories, third-party
boundaries, and interprocedural inference are deliberately outside the
check's scope.
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.