Electric.Shapes.Filter (electric v1.4.13)

View Source

Responsible for knowing which shapes are affected by a change.

affected_shapes(filter, change) will return a set of IDs for the shapes that are affected by the change considering all the shapes that have been added to the filter using add_shape/3.

The Filter module keeps track of what tables are referenced by the shapes and changes and delegates the table specific logic to the Filter.WhereCondition module.

Data is stored in ETS tables (outside the process heap) to avoid GC pressure with large numbers of shapes.

Summary

Functions

Add a shape for the filter to track.

Returns the shape IDs for all shapes that have been added to the filter that are affected by the given change.

Get a shape by its ID. Used internally for where clause evaluation.

Returns true if a dep shape is registered in the sublink inverted index.

Remove a shape from the filter.

Types

shape_id()

@type shape_id() :: any()

t()

@type t() :: %Electric.Shapes.Filter{
  eq_index_table: term(),
  incl_index_table: term(),
  refs_fun: term(),
  shapes_table: term(),
  stack_id: term(),
  sublink_dep_table: term(),
  sublink_field_table: term(),
  sublink_shapes_set: term(),
  tables_table: term(),
  where_cond_table: term()
}

Functions

active_shapes(filter)

@spec active_shapes(t()) :: [shape_id()]

add_shape(filter, shape_id, shape)

@spec add_shape(t(), shape_id(), Electric.Shapes.Shape.t()) :: t()

Add a shape for the filter to track.

The shape_id can be any term you like to identify the shape. Whatever you use will be returned by affected_shapes/2 when the shape is affected by a change.

affected_shapes(filter, change)

Returns the shape IDs for all shapes that have been added to the filter that are affected by the given change.

get_shape(filter, shape_id)

Get a shape by its ID. Used internally for where clause evaluation.

has_shape?(filter, shape_handle)

@spec has_shape?(t(), shape_id()) :: boolean()

new(opts \\ [])

@spec new(keyword()) :: t()

registered_in_inverted_index?(filter, shape_id)

@spec registered_in_inverted_index?(t(), shape_id()) :: boolean()

Returns true if a dep shape is registered in the sublink inverted index.

Only dep shapes in top-level other_shapes (non-optimisable WHERE) are registered. Dep shapes that go through an equality index end up in nested other_shapes and must be evaluated normally by other_shapes_affected.

remove_shape(filter, shape_id)

@spec remove_shape(t(), shape_id()) :: t()

Remove a shape from the filter.