Electric.Shapes.Filter.WhereCondition (electric v1.4.13)

View Source

Responsible for knowing which shapes are affected by a change to a specific table.

When add_shape/4 is called, shapes are added to a tree stored in ETS. Each node on the tree represents an optimised (indexed) condition in the shape's where clause, with shapes that share an optimised condition being on the same branch.

Each WhereCondition is identified by a unique reference and stores:

  • index_keys: MapSet of {field, operation} tuples for indexed conditions
  • other_shapes: map of shape_id -> where_clause for non-optimized shapes

The logic for specific indexes (equality, inclusion) is handled by dedicated modules that also use ETS.

Summary

Functions

add_shape(filter, condition_id, shape_id, where_clause)

affected_shapes(filter, condition_id, record)

all_shape_ids(filter, condition_id)

init(filter, condition_id)

remove_shape(filter, condition_id, shape_id, where_clause)

@spec remove_shape(
  Electric.Shapes.Filter.t(),
  reference(),
  String.t(),
  Electric.Replication.Eval.Expr.t() | nil
) :: :deleted | :ok

Remove a shape from a WhereCondition.

Returns :deleted if the condition is now empty and was deleted, or :ok if the condition still has shapes.