View Source Indexed.Actions.Warm (Indexed v0.0.1)

Holds internal state info during operations.

Link to this section Summary

Types

Data option for warming the cache. If data_tuple, the given ordering is explicit and we can assume it's correct and skip a sorting routine.

A list of records, wrapped in a hint about a field and direction it's already sorted by.

t()
  • :data_tuple - full input data set with order/direction hint
  • :entity_name - entity name atom (eg. :cars)
  • :id_key - Specifies how to find the id for a record. See Indexed.Entity.t/0.
  • :index_ref - ETS table reference for storing index data

Functions

Return a list of all ids from the collection.

From a field, make a compare function, suitable for Enum.sort/2.

Normalize warm/1's data option.

Normalize the prefilters option to tuples, adding nil prefilter if needed.

For a set of entities, load data and indexes to ETS for each.

Create the asc and desc indexes for one field.

Link to this section Types

@type data_opt() :: data_tuple() | Indexed.record() | [Indexed.record()] | nil

Data option for warming the cache. If data_tuple, the given ordering is explicit and we can assume it's correct and skip a sorting routine.

@type data_tuple() ::
  {sort_dir :: :asc | :desc, sort_field :: atom(), [Indexed.record()]}

A list of records, wrapped in a hint about a field and direction it's already sorted by.

@type t() :: %Indexed.Actions.Warm{
  data_tuple: data_tuple(),
  entity_name: atom(),
  id_key: any(),
  index_ref: :ets.tid()
}
  • :data_tuple - full input data set with order/direction hint
  • :entity_name - entity name atom (eg. :cars)
  • :id_key - Specifies how to find the id for a record. See Indexed.Entity.t/0.
  • :index_ref - ETS table reference for storing index data

Link to this section Functions

Link to this function

id_list(collection, id_key)

View Source
@spec id_list([Indexed.record()], any()) :: [Indexed.id()]

Return a list of all ids from the collection.

@spec record_sort_fn(Indexed.Entity.field()) :: (any(), any() -> boolean())

From a field, make a compare function, suitable for Enum.sort/2.

Link to this function

resolve_data_opt(data, entity_name, fields)

View Source
@spec resolve_data_opt(data_opt(), atom(), [Indexed.Entity.field()]) ::
  {atom(), atom(), [Indexed.record()]}

Normalize warm/1's data option.

Link to this function

resolve_fields_opt(fields, entity_name)

View Source
@spec resolve_fields_opt([atom() | Indexed.Entity.field()], atom()) :: [
  Indexed.Entity.field()
]

Normalize fields.

Link to this function

resolve_prefilters_opt(prefilters)

View Source
@spec resolve_prefilters_opt([atom() | keyword()] | nil) :: keyword(keyword())

Normalize the prefilters option to tuples, adding nil prefilter if needed.

@spec run(keyword()) :: Indexed.t()

For a set of entities, load data and indexes to ETS for each.

Argument is a keyword list where entity name atoms are keys and keyword lists of options are values. Allowed options are as follows:

  • :data - List of maps (with id key) -- the data to index and cache. Required. May take one of the following forms:
    • {direction, field, list} - data list, with a hint that it is already sorted by field (atom) and direction (:asc or :desc), data_tuple/0.
    • list - data list with unknown ordering; must be sorted for every field.
  • :fields - List of field name atoms to index by. At least one required.
    • If field is a DateTime, use sort: {:my_field, sort: :date_time}.
    • Ascending and descending will be indexed for each field.
  • :id_key - Primary key to use in indexes and for accessing the records of this entity. See Indexed.Entity.t/0. Default: :id.
  • :prefilters - List of field name atoms which should be prefiltered on. This means that separate indexes will be managed for each unique value for each of these fields, across all records of this entity type. While field name nil refers to the indexes where no prefilter is used (all records) and it is included by default, it may be defined in the arguments if further options are needed. Default [{nil, []}]. If options are needed, 2-element tuples may be used in place of the atom where the the first element is the field name atom, and the second is a keyword list of any of the following options:
    • :maintain_unique - List of field name atoms for which a list of unique values under the prefilter will be managed. If the nil prefilter is defined, leave the other prefilter fields off the :maintain_unique option as these are automatically included. These lists can be fetched via get_uniques_list/4.
Link to this function

warm_index(warm, prefilter, field, arg4)

View Source
@spec warm_index(t(), Indexed.prefilter(), Indexed.Entity.field(), data_tuple()) ::
  true

Create the asc and desc indexes for one field.