EctoNPlusOne (EctoNPlusOne v0.1.0)

Copy Markdown View Source

Detect n+1 queries in Ecto.

Summary

Types

Detection options.

An Ecto Repo module or a non-empty list of Repo modules.

Functions

Attach the telemetry handler to one or more of your Ecto repos.

Detach the telemetry handler.

Types

option()

@type option() ::
  {:threshold, pos_integer()}
  | {:min_parameter_variants, pos_integer()}
  | {:application_modules, [module()]}
  | {:operations, :all | [atom()]}
  | {:ignore, (map() -> as_boolean(term()))}
  | {:include_params, boolean()}
  | {:max_samples, non_neg_integer()}
  | {:max_queries, pos_integer()}
  | {:window_ms, pos_integer()}
  | {:on_detect, (EctoNPlusOne.Detection.t() -> term())}

Detection options.

  • :threshold (pos_integer/0) - minimum matching queries The default value is 5.

  • :min_parameter_variants (pos_integer/0) - minimum distinct parameter sets The default value is 1.

  • :application_modules (a non-empty list of top-level modules) - Required. require a stacktrace frame inside an application module namespace

  • :operations (:all or a list of SQL operation names) - SQL operations to inspect The default value is [:select].

  • :ignore (function of arity 1) - predicate receiving a normalized query candidate

  • :include_params (boolean/0) - retain parameter samples The default value is false.

  • :max_samples (non_neg_integer/0) - maximum retained parameter lists The default value is 3.

  • :max_queries (pos_integer/0) - maximum distinct query shapes retained per process The default value is 1000.

  • :window_ms (pos_integer/0) - inactivity window for query groups The default value is 2000.

  • :on_detect (function of arity 1) - Required. handler invoked when a query group crosses the thresholds

repos()

@type repos() :: module() | [module()]

An Ecto Repo module or a non-empty list of Repo modules.

Functions

attach(repos, opts)

@spec attach(repos(), [option()]) :: :ok

Attach the telemetry handler to one or more of your Ecto repos.

Do this once in your main application.ex file.

detach(repos)

@spec detach(repos()) :: :ok

Detach the telemetry handler.